想在UIAlertView中显示UIProgressView(want to display UIP

2019-06-26 13:10发布

嗨,大家好,我想在UIAlertView中显示UIProgressView显示该文件的上传的处理,但我已经搜索了太多,也找到了该链接,但门槛不能做到这一点的。 我不从这个想法得到

如果有人知道做到这一点的最简单的方法,那么请让我知道。 我应该心存感激。

Answer 1:

试试这个代码...

UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIProgressView *pv = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
pv.frame = CGRectMake(20, 20, 200, 15);
pv.progress = 0.5;
[av addSubview:pv];
[av show];


Answer 2:

我有问题,这样做,并结束了与此:

av = [[UIAlertView alloc] initWithTitle:@"Running" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
progressView.frame = CGRectMake(0, 0, 200, 15);
progressView.bounds = CGRectMake(0, 0, 200, 15);
progressView.backgroundColor = [UIColor blackColor];

[progressView setUserInteractionEnabled:NO];
[progressView setTrackTintColor:[UIColor blueColor]];
[progressView setProgressTintColor:[UIColor redColor]];
[av setValue:progressView forKey:@"accessoryView"];

[av show];


Answer 3:

虽然这并不完全回答你的问题,尝试MBProgressHud ,具有此功能的内置第三方控制。 在Github上提供的例子应该让你能很快的速度。



Answer 4:

试试这个代码。 将是对活动的指标和NO的progressView

- (void) createProgressionAlertWithMessage:(NSString *)message withActivity:(BOOL)activity
{
 progressAlert = [[UIAlertView alloc] initWithTitle: message
 message: @"Please wait..."
 delegate: self
 cancelButtonTitle: nil
 otherButtonTitles: nil];


 // Create the progress bar and add it to the alert
 if (activity) {
 activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
 activityView.frame = CGRectMake(139.0f-18.0f, 80.0f, 37.0f, 37.0f);
 [progressAlert addSubview:activityView];
 [activityView startAnimating];
 } else {
 progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30.0f, 80.0f, 225.0f, 90.0f)];
 [progressAlert addSubview:progressView];
 [progressView setProgressViewStyle: UIProgressViewStyleBar];
 }
 [progressAlert show];
 [progressAlert release];
}


Answer 5:

为什么不利用alerviewdelegate方法

- (void)willPresentAlertView:(UIAlertView *)alertView

这样做的好处是,我们可以看到大小alertview实际上是在屏幕上,因为iOS的已预先计算这在这一点上,所以不需要幻数 - 或覆盖苹果公司警告反对阶级!

随着iOS7的我记得读从苹果公司说,一些文件没有硬编码任何帧大小,但总是从应用程序,或类似的规定计算呢?

- (void)willPresentAlertView:(UIAlertView *)alertView
{
   CGRect alertRect = alertview.bounds;
   UIProgressView *loadingBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
   loadingBar.bounds = CGRectMake(0, 0, alertRect.width, HEIGHT_YOU_WANT);
   //  Do what ever you want here to set up the alertview, as you have all the details you need
   //  Note the status Bar will always be there, haven't found a way of hiding it yet
   //  Suggest adding an objective C reference to the original loading bar if you want to manipulate it further on don't forget to add #import <objc/runtime.h>
   objc_setAssociatedObject(alertView, &myKey, loadingBar, OBJC_ASSOCIATION_RETAIN); // Send the progressbar over to the alertview
}

拉参考承重横条

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

然后使用

UIProgressView *loadingBar = objc_getAssociatedObject(alertView, &myKey);

请记住,定义

#import <objc/runtime.h>
static char myKey;

在类声明的顶部



Answer 6:

这是创建一个警报视图

UIAlertController *警报= [UIAlertController alertControllerWithTitle:@ “消息” 消息:@ “这是测试” preferredStyle:UIAlertControllerStyleAlert];

现在添加文本框

[alert addTextFieldWithConfigurationHandler:^(UITextField *textField)
 {
     textField.placeholder=@"Enter Text label";
     [textField setBorderStyle:UITextBorderStyleRoundedRect];
     textField.backgroundColor=[UIColor whiteColor];
 }];

并加入其上视图

[自presentViewController:警报动画:YES完成:无];



文章来源: want to display UIProgressView on UIAlertView