【发布时间】:2009-06-02 18:53:19
【问题描述】:
我想创建一个 UIAlertView,它会说“...进行中”。它还会显示 UIActivityindicatorView 就可以了。你能告诉我该怎么做吗?
谢谢。
【问题讨论】:
标签: iphone
我想创建一个 UIAlertView,它会说“...进行中”。它还会显示 UIActivityindicatorView 就可以了。你能告诉我该怎么做吗?
谢谢。
【问题讨论】:
标签: iphone
它非常简单。只需创建一个 UIActivityIndicatorView 并将其作为子视图添加到 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];
【讨论】:
在我的情况下,我发现使用硬编码的帧来源很糟糕。如果我的消息多行,指示器会显示在我的消息顶部。
所以我创建带有布局指示器的函数,如果大小为 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;
}
在这种情况下,指示器总是按中心
一行消息:
多一行留言:
【讨论】:
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];
【讨论】: