速攻でUIAlertControllerを作る – Swift4 iOs

環境

  • UIAlertController
  • Alert
  • swift
  • swift4
  • swift3
  • xcode
  • xcode9
  • iOS

実装

 let alertController = UIAlertController(title: "アラート", message: "アラートのサンプルです", preferredStyle: .alert)

            let action1 = UIAlertAction(title: "デフォルト", style: .default) { (action:UIAlertAction) in
                print("デフォルトが押された");
            }

            let action2 = UIAlertAction(title: "キャンセル", style: .default) { (action:UIAlertAction) in
                print("キャンセルが押された");
            }

            let action3 = UIAlertAction(title: "アド", style: .destructive) { (action:UIAlertAction) in
                print("アドが押された");
            }

            alertController.addAction(action1)
            alertController.addAction(action2)
            alertController.addAction(action3)
            self.present(alertController, animated: true, completion: nil)

参照

How to use UIAlertController in Swift.

藤沢瞭介(Ryosuke Hujisawa)
  • りょすけと申します。18歳からプログラミングをはじめ、今はフロントエンドでReactを書いたり、AIの勉強を頑張っています。off.tokyoでは、ハイテクやガジェット、それからプログラミングに関する情報まで、エンジニアに役立つ情報を日々発信しています!

未整理記事