swift alert actionsheet 스위프트 얼럿 액션시트 




//

//  ViewController.swift

//  SimpleAlert

//

//  Created by stayfoolish on 22/11/2018.

//  Copyright © 2018 stayfoolish. All rights reserved.

//


import UIKit


class ViewController: UIViewController {


    override func viewDidLoad() {

        super.viewDidLoad()

        // Do any additional setup after loading the view, typically from a nib.

    }


    @IBAction func alertButton(_ sender: UIButton) {

        

        let alert: UIAlertController

        alert = UIAlertController(title: "얼럿입니다", message: "여기에 메세지를 남길 수 있어요 사용자에게 왜 이 얼럿을 보여줬는지 설명합니다", preferredStyle: UIAlertController.Style.alert)

        

     

        

        var cancelAction: UIAlertAction

        cancelAction = UIAlertAction(title: "취소", style: UIAlertAction.Style.cancel, handler: {( action: UIAlertAction) in

            print("취소 액션 선택함")

            

        })

        

        var defaultAction: UIAlertAction

        defaultAction = UIAlertAction(title: "확인", style: UIAlertAction.Style.default, handler: {( action: UIAlertAction) in

            print("확인 액션 선택함")

            

        })

        

        var destructiveAction: UIAlertAction

        destructiveAction = UIAlertAction(title: "destructive", style: UIAlertAction.Style.destructive, handler: {( action: UIAlertAction) in

            print("destructive 액션 선택함")

            

        })

        

        alert.addAction(cancelAction)

        alert.addAction(defaultAction)

        alert.addAction(destructiveAction)

        

        self.present(alert, animated: true ) {

            print("얼럿 보여짐")

        }

    }

    

    

    @IBAction func actionSheetButton(_ sender: UIButton) {

        let alert: UIAlertController

        alert = UIAlertController(title: "얼럿입니다", message: "여기에 메세지 남길 수 있어요", preferredStyle: UIAlertController.Style.actionSheet)

        

        var cancelAction: UIAlertAction

        cancelAction = UIAlertAction(title: "취소", style: UIAlertAction.Style.cancel, handler: { (action: UIAlertAction) in

            print("취소 액션시트 선택함")

        })

        

        var defaultAction: UIAlertAction

        defaultAction = UIAlertAction(title: "확인", style: UIAlertAction.Style.default, handler: { (action: UIAlertAction) in

            print("확인 액션시트 선택함")

        })

        

        var destructiveAction: UIAlertAction

        destructiveAction = UIAlertAction(title: "destructive", style: UIAlertAction.Style.destructive, handler: { (action: UIAlertAction) in

            print("destructive 액션시트 선택함")

        })

        

        alert.addAction(cancelAction)

        alert.addAction(defaultAction)

        alert.addAction(destructiveAction)

        

        

        self.present(alert,animated: true){

            print("얼럿 보여짐")

        }

    }

    

}















+ Recent posts