在UIAlertView中添加UIActivityindicatorView

eba*_*unt 15 iphone

我想创建一个UIAlertView,它会说"......正在进行中".它还将显示UIActivityindicatorView就可以了.你能让我知道我该怎么办?

谢谢.

Bra*_*ker 41

它非常简单.只需创建一个UIActivityIndi​​catorView并将其作为子视图添加到UIAlertView.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" " message:@" " delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
    progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    [alert addSubview:progress];
    [progress startAnimating];

    [alert show];
Run Code Online (Sandbox Code Playgroud)

  • [alert dismissWithClickedButtonIndex:0 animated:YES]; (4认同)
  • 对于iOS7,无法将子视图添加到UIAlertView!参考[this](http://stackoverflow.com/questions/18759206/how-to-add-subview-inside-uialertview-for-ios-7) (3认同)
  • 不是我知道的.它不使用任何私有API.虽然很久以前,我已经批准了这段代码. (2认同)