iOS中是否有与Android ProgressDialog等效的功能?

6
在Android开发中,我使用ProgressDialog来创建一个带有“旋转”、一些文本和取消按钮的对话框。我将其与CountdownTimer结合使用,在10秒后执行操作,除非用户取消对话框。
我已经搜索了iOS中的等效物,例如开源的SVProgressHUD和MBProgressHUD,但似乎没有支持添加按钮的选项。
我需要自己编写代码吗?还是有人知道实现这个功能的简单方法?

1
自从 IOS 9.0 版本以后,UIAlertView 已经被弃用。请参考 此链接 获取更新的解决方案! - Lazar Kukolj
尝试使用Swift编写的HUD库,链接为https://github.com/shubh10/JustHUD。 - Shubham Naik
1个回答

8
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
indicator.center = self.view.center;    
[self.view addSubview:indicator];
[indicator bringSubviewToFront:self.view];
[UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;

当您想要显示指示器时,请编写以下代码:

[indicator startAnimating];

当您想隐藏指示器时,请编写以下代码:
[indicator stopAnimating];

我在如何在 iPhone 应用程序中编程添加简单的默认加载(进度)栏找到了这个内容。

更新:你可以创建一个没有按钮的提示对话框,并手动添加任何自定义元素:

UIAlertView *alert;

...

alert = [[UIAlertView alloc] initWithTitle:@"\n\nConfiguring Preferences\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil]; //display without any btns
// alert = [[UIAlertView alloc] initWithTitle:@"\n\nConfiguring Preferences\nPlease Wait..." message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil]; //to display with cancel btn
[alert show];

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];

为了关闭警告框,只需执行以下操作。
[alert dismissWithClickedButtonIndex:0 animated:YES];

更多信息请参考:http://iosdevelopertips.com/user-interface/uialertview-without-buttons-please-wait-dialog.html


更新答案,采用新方法。 - Vi Matviichuk
这样做就可以了,谢谢。为了显示取消按钮需要进行一个更改:alert = [[UIAlertView alloc] initWithTitle:@"\n\n配置首选项\n请稍等..." message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles: nil]; - Gary Wright
如果您的问题已解决,请将答案标记为“已解决”。 - Vi Matviichuk
完成了,我刚刚在编辑我的评论并进行了必要的修改。 - Gary Wright
将您的代码片段添加到答案中。 - Vi Matviichuk
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接