swift 개발

[swift] action sheet 사용하기

arcjeen 2017. 8. 22. 20:09

action sheet 사용하기


action sheet = 아래에서 튀어나오는 메뉴. 보통 프로필이미지 지정 옵션을 줄때 사용.



        //action sheet title 지정

        let optionMenu = UIAlertController(title: nil, message: "Choose Option", preferredStyle: .actionSheet)

        

        //옵션 초기화

        let deleteAction = UIAlertAction(title: "Delete", style: .default, handler: {

            (alert: UIAlertAction!) -> Void in

        })

        let saveAction = UIAlertAction(title: "Save", style: .default, handler: {

            (alert: UIAlertAction!) -> Void in

        })

        

        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: {

            (alert: UIAlertAction!) -> Void in

      })

    

       //action sheet 옵션 추가.

        optionMenu.addAction(deleteAction)

        optionMenu.addAction(saveAction)

        optionMenu.addAction(cancelAction)

        

       //show

        self.present(optionMenu, animated: true, completion: nil)

        


delete, save, cancle등 원하는 옵션을 넣어서 초기화되면 된다. 원래는 actionsheet라는 클래스가 있었지만 


이제는 UIalertontroller로 대체!