天天看點

iOS 10 UIActionSheet UIAlertController

iOS 8 廢棄了UIActionSheet, 現在使用UIAlertController

// actionSheet 樣式的AlertController
let actionSheet =  UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.actionSheet)

// 添加一個Button
 let someButton = UIAlertAction(title: "Button", style: UIAlertActionStyle.default) { (alert) -> Void in
       //do something
}

// 取消
let cacelButton = UIAlertAction(title:"Cancel",style: UIAlertActionStyle.cancel, handler: nil)

actionSheet.addAction(someButton)
actionSheet.addAction(cancelButton)

// 在view controller的某個地方 present
self.present(actionSheet, animated: true, completion: nil)