【问题标题】:Is there an equivalent in iOS to the Android ProgressDialog [duplicate]iOS 中是否有与 Android ProgressDialog 等效的功能 [重复]
【发布时间】:2014-11-25 13:49:41
【问题描述】:

在 Android 开发中,我使用 ProgressDialog 给我一个带有“spinny”、一些文本和一个取消按钮的对话框。我将它与 CountdownTimer 结合使用,在 10 秒后执行操作,除非用户取消对话框。

我在 iOS 中搜索过类似的东西,例如开源的 SVProgressHUD 和 MBProgressHUD,但似乎没有一个支持添加按钮。

我必须自己写吗,还是有人知道实现这一点的简单方法?

【问题讨论】:

  • 因为 IOS 9.0 UIAlertView 已被弃用。关注this 获取最新答案!
  • 在 swift 中试用这个适用于 iOS 的 HUD 库github.com/shubh10/JustHUD

标签: android ios progressdialog


【解决方案1】:
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];

发现于How to programmatically add a simple default loading(progress) bar in iphone app

UPD:您可以创建不带按钮的警报对话框并手动添加任何自定义元素:

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

【讨论】:

  • 感谢您的回答,虽然这显示了一个我以后可以关闭的 spinny,但它没有提供取消按钮的选项。
  • 用新方法更新答案
  • 做到了,谢谢,需要进行一项更改才能显示取消按钮:alert = [[UIAlertView alloc] initWithTitle:@"\n\n配置首选项\n请稍候..." 消息:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil];
  • 如果确实如此,您可以将答案标记为“解决了我的问题”
  • 完成,我只是在编辑我的评论并进行必要的修改。
猜你喜欢
  • 2011-03-31
  • 1970-01-01
  • 1970-01-01
  • 2023-03-11
  • 2014-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多