将UIActivityIndi​​catorView添加到UIAlertView

时间:2014-04-15 09:40:22

标签: ios objective-c uialertview uiactivityindicatorview

我想在消息中添加一个活动指示器,uiAlert消息,我基本上尝试了互联网上的所有内容,没有任何对我有用,我只会单独使用uialertview,这里是我的代码

UIAlertView  *waitAlert = [[UIAlertView alloc] initWithTitle:@"Please Wait...." message:@"\n\n" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame: CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
progress.color = [UIColor blackColor];
[waitAlert addSubview: progress];
[progress startAnimating];
[waitAlert show];

这就是我最终的结果 enter image description here

我错过了什么!?

2 个答案:

答案 0 :(得分:1)

在iOS 7中你不能在UIAlertView上添加任何内容,这可能直到iOS 6.1。所以MBProgressHud是最好的和简单的解决方案

答案 1 :(得分:0)

尝试使用UIActivityIndicator方法添加UIAlertViewDelegate

- (void)didPresentAlertView:(UIAlertView *)alertView
{
    UIActivityIndicatorView *progress = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    progress.frame = CGRectMake(125, 50, 30, 30);

    [progress startAnimating];
    [alertView addSubview:progress];
}
相关问题