以下代码在iOS 5到6.1中运行良好.我甚至在应用程序中存储了该代码:
-(void)showActivityIndicator
{
if(!mLoadingView) //
{
mLoadingView = [[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
mLoadingView.tag = kAlertViewTag;
}
[mLoadingView show];
}
- (void)willPresentAlertView:(UIAlertView *)alertView
{
if (alertView.tag == kAlertViewTag)
{
UIActivityIndicatorView *actInd = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
actInd.frame = CGRectMake(128.0f, 45.0f, 25.0f, 25.0f);
[alertView addSubview:actInd];
[actInd startAnimating];
UILabel *l = [[UILabel alloc]init];
l.text = NSLocalizedString(@"PRODUCT_PURCHASE_INDICATOR_TITLE", @"Please wait...");
l.font = [UIFont fontWithName:@"Helvetica" size:16];
float strWidth = [l.text sizeWithFont:l.font].width;
float frameWidth = alertView.frame.size.width;
l.frame = CGRectMake((frameWidth - strWidth)/2, -25, 210, 100); …Run Code Online (Sandbox Code Playgroud)