如果您只需要一个进度条,只需将其添加为子视图,如下所示:
更新为 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!)
})
斯威夫特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
对于更大的内容,但对于进度条,这应该可以解决问题。