Skip to content

ActionSheet 2

Mohammad Azmal Hossain edited this page Mar 6, 2017 · 1 revision

import UIKit

class MainViewController: UIViewController, UIActionSheetDelegate {

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.gray
// Create the AlertController
let actionSheetController = UIAlertController(title: "Please select", message: "How you would like to utilize the app?", preferredStyle: .actionSheet)
// Create and add the Cancel action
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { action -> Void in
  // Just dismiss the action sheet
}
actionSheetController.addAction(cancelAction)
// Create and add first option action
let takePictureAction = UIAlertAction(title: "Consumer", style: .default) { action -> Void in
  self.performSegue(withIdentifier: "segue_setup_customer", sender: self)
}
actionSheetController.addAction(takePictureAction)
// Create and add a second option action
let choosePictureAction = UIAlertAction(title: "Service provider", style: .default) { action -> Void in
  self.performSegue(withIdentifier: "segue_setup_provider", sender: self)
}
actionSheetController.addAction(choosePictureAction)
// We need to provide a popover sourceView when using it on iPad
//  // actionSheetController.popoverPresentationController?.sourceView = sender as UIView
// Present the AlertController
self.present(actionSheetController, animated: true, completion: nil)

}

}

Clone this wiki locally