Skip to content

Instantly share code, notes, and snippets.

@TechMaster
Created June 30, 2017 05:20
Show Gist options
  • Select an option

  • Save TechMaster/b51c759ef72fff37bcdef5aef8bedc5b to your computer and use it in GitHub Desktop.

Select an option

Save TechMaster/b51c759ef72fff37bcdef5aef8bedc5b to your computer and use it in GitHub Desktop.
ShowAlertView.swift
//
// ViewController.swift
// DisplayAlert
//
// Created by cuong on 6/30/17.
// Copyright © 2017 Techmaster. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated);
self.showAlert()
}
func showAlert() {
let actionSheetController: UIAlertController = UIAlertController(title: "Action Sheet", message: "Swiftly Now! Choose an option!", preferredStyle: .actionSheet)
//Create and add the Cancel action
let cancelAction: UIAlertAction = 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 = UIAlertAction(title: "Take Picture", style: .default) { action -> Void in
//Code for launching the camera goes here
}
actionSheetController.addAction(takePictureAction)
//Create and add a second option action
let choosePictureAction: UIAlertAction = UIAlertAction(title: "Choose From Camera Roll", style: .default) { action -> Void in
//Code for picking from camera roll goes here
}
actionSheetController.addAction(choosePictureAction)
//Present the AlertController
self.present(actionSheetController, animated: true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment