四步曲:
1、创建UIAlertController 警告控制器
2、创建UIAlertAction 警告行为
3、将UIAlertAction 添加到UIAlertController
4、present出UIAlertController 警告控制器
直接上代码
import UIKit
class ViewController: UIViewController {
var controller:UIAlertController?
override func viewDidLoad() {
super.viewDidLoad()
controller = UIAlertController(
title: "Choose how you would like to share this photo",
message: "You cannot bring back a deleted photo",
preferredStyle: .ActionSheet)
let actionEmail = UIAlertAction(title: "Via email",
style: UIAlertActionStyle.Default,
handler: {(paramAction:UIAlertAction!) in
/* Send the photo via email */
})
let actionImessage = UIAlertAction(title: "Via iMessage",0)"> /* Send the photo via iMessage */
})
let actionDelete = UIAlertAction(title: "Delete photo",175)"> style: UIAlertActionStyle.Destructive,0)"> /* Delete the photo here */
})
controller!.addAction(actionEmail)
controller!.addAction(actionImessage)
controller!.addAction(actionDelete)
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.presentViewController(controller!,animated: true,completion: nil)
}
}