2009-06-02 69 views
15

添加UIActivityindicatorView我想创建一个UIAlertView中会说“......在进步”。它也会显示出它的UIActivityindicatorView。你能让我知道我该怎么做?在UIAlertView中

谢谢。

回答

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]; 
+0

谢谢,它工作。 – ebaccount 2009-06-03 20:34:48

+0

这是很好的答案,但我想知道如果没有按钮我怎么能从视图中解雇它? – 2011-09-02 08:48:49

+4

[alert dismissWithClickedButtonIndex:0 animated:YES]; – 2011-09-02 16:20:12

0
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:nil]; 
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
spinner.center = CGRectMake(xcords, ycords, width, height); 
[alert addSubview:spinner]; 
[spinner startanimating]; 
[alert show]; 

,此微调被隐藏在AlertView的解雇。

[alert dismissWithClickedButtonIndex:0 animated:YES]; 
2

在我的情况下,我发现使用硬编码帧起源的是坏的。如果我的消息有更多的一行,指示器显示我的消息的顶部。

所以我创建功能与布点指示器如果尺寸UIAlertView中

+(UIAlertView*) progressAlertWithTitle:(NSString*) title andMessage:(NSString*) message andDelegate:(id)delegate{ 
    UIAlertView *progressAlert = [[UIAlertView alloc] init]; 
    [progressAlert setTitle:title]; 
    [progressAlert setMessage:message]; 
    [progressAlert setDelegate:delegate]; 
    UIActivityIndicatorView *progress=nil; 
    progress= [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 

    [progressAlert addSubview:progress]; 
    [progress startAnimating]; 

    [progressAlert show]; 

    progress.frame=CGRectMake(progressAlert.frame.size.width/2-progress.frame.size.width, progressAlert.frame.size.height-progress.frame.size.height*2, progress.frame.size.width, progress.frame.size.height); 


    return progressAlert; 
} 

在这种情况下,指示符总是由中心

一行消息:

enter image description here

更多一行消息:

enter image description here