答案 0 :(得分:3)
您可以使用此代码来实现此目的。这适用于Swift 3和XCode 8。
let actionSheet: UIAlertController = UIAlertController.init(title: "Title of the action sheet", message: "Message to display", preferredStyle: .actionSheet)
//Create and add the Cancel action
let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel) { action -> Void in
//Just dismiss the action sheet
}
actionSheet.addAction(cancelAction)
//Create and add first option action
let savePictureAction: UIAlertAction = UIAlertAction(title: "Using Camera", style: .default) { action -> Void in
// Write Save Method Here
}
actionSheet.addAction(savePictureAction)
//Create and add a second option action
let sendInMessenger: UIAlertAction = UIAlertAction(title: "Choose Existing Photo", style: .default) { action -> Void in
// Write your code to Send In Messenger Here
}
actionSheet.addAction(sendInMessanger)
//Create and add a third option action
let dontLikePhoto: UIAlertAction = UIAlertAction(title: "Choose Existing Photo", style: .default) { action -> Void in
// Write your code if you Don't like photo Here
}
actionSheet.addAction(dontLikePhoto)
//Create and add a third option action
let trunOnNotification: UIAlertAction = UIAlertAction(title: "Choose Existing Photo", style: .default) { action -> Void in
// Write your code Turn on Notifications Here
}
actionSheet.addAction(trunOnNotification)
//We need to provide a popover sourceView when using it on iPad
actionSheet.popoverPresentationController?.sourceView = sender as? UIView
//Present the AlertController
self.present(actionSheet, animated: true, completion: nil)
请注意,此方法可从iOS 9获得。