iOS/iOS Swift 개발 일기

[iOS swift] actionsheet 액션시트 만들기

Developer-Michelle 2022. 8. 23. 19:38
let alertController = UIAlertController(title: nil, message: "Takes the appearance of the bottom bar if specified; otherwise, same as UIActionSheetStyleDefault.", preferredStyle: .ActionSheet)

let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in
  // ...
 }
 alertController.addAction(cancelAction)

let OKAction = UIAlertAction(title: "OK", style: .Default) { (action) in
   // ...
}
alertController.addAction(OKAction)

let destroyAction = UIAlertAction(title: "Destroy", style: .Destructive) { (action) in
println(action)
}
alertController.addAction(destroyAction)

self.presentViewController(alertController, animated: true) {
// ...
}

 

위에꺼 이용하거나,

snippet에 등록해놓은 'alert ()' 관련에다가 여러개 붙여 쓰면 그게 액션시트가 됨

 

 

alert () 관련 코드 :

 

let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)

        let cancel = UIAlertAction(title: "취소", style: .cancel)

        let ok = UIAlertAction(title: buttonTitle, style: .default,  handler: buttonAction)

        alert.addAction(cancel)

        alert.addAction(ok)

        self.present(alert, animated: true)