krsakai / iOSStudy

1 stars 0 forks source link

UIAlertController #24

Closed krsakai closed 7 years ago

krsakai commented 7 years ago

AlertController

UIKitで用意されているアラート表示の仕組み 警告を表示する際などに便利。レストランボードは独自のデザインのアラートを用意しているので使わないが、一般的にはよく使う

使い方

let alert = UIAlertController(title: "アラート", message: "メッセージ", preferredStyle: .alert)
// ↓アクションシートの場合は以下
// let alert = UIAlertController(title: "アラート", message: "メッセージ", preferredStyle: .actionSheet)
let action1 = UIAlertAction(title: "OK", style: .default) { _ in
    print("OKが押された時の処理")
}

let action2 = UIAlertAction(title: "キャンセル", style: .cancel) { _ in
    print("キャンセルが押された時の処理")
}
alert.addAction(action1)
alert.addAction(action2)
present(alert, animated: true, completion: nil)

■ キャプチャ