如何将进度条添加到UIAlertController? [英] How to add Progress bar to UIAlertController?
本文介绍了如何将进度条添加到UIAlertController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在快速的iOS 8 UIAlertController中添加进度条.这可能吗? 有什么方法可以继承UIAlertController并添加progres bar并连接一些委托函数?
I want to add progress bar in swift iOS 8 UIAlertController. Is this possible? Is there any way to subclass UIAlertController and add progres bar and connect some delegate functions?
谢谢
推荐答案
如果只需要进度条,则可以简单地将其添加为子视图,如下所示:
If you just need a progressbar you can simply add it as a subview as follows:
已针对Swift 5更新:
// Just create your alert as usual:
let alertView = UIAlertController(title: "Please wait", message: "Need to download some files.", preferredStyle: .alert)
alertView.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
// Show it to your users
present(alertView, animated: true, completion: {
// Add your progressbar after alert is shown (and measured)
let margin:CGFloat = 8.0
let rect = CGRect(x: margin, y: 72.0, width: alertView.view.frame.width - margin * 2.0 , height: 2.0)
self.progressView = UIProgressView(frame: rect)
self.progressView!.progress = 0.5
self.progressView!.tintColor = self.view.tintColor
alertView.view.addSubview(self.progressView!)
})
Swift 2.0:
// Just create your alert as usual:
let alertView = UIAlertController(title: "Please wait", message: "Need to download some files.", preferredStyle: .Alert)
alertView.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
// Show it to your users
presentViewController(alertView, animated: true, completion: {
// Add your progressbar after alert is shown (and measured)
let margin:CGFloat = 8.0
let rect = CGRectMake(margin, 72.0, alertView.view.frame.width - margin * 2.0 , 2.0)
let progressView = UIProgressView(frame: rect)
progressView.progress = 0.5
progressView.tintColor = UIColor.blueColor()
alertView.view.addSubview(progressView)
})
要增大内容的大小,很难调整UIAlertController
的大小,但是对于进度条,这应该可以解决问题.
It's quite difficult to resize the UIAlertController
for bigger content but for a progressbar this should do the trick.
这篇关于如何将进度条添加到UIAlertController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文