LoginSignup
0
2

More than 3 years have passed since last update.

アラートの表示

Last updated at Posted at 2019-05-24

ezgif.com-optimize.gif

iOSアプリを作成していく中で必須のアラートの作り方について説明していきます。

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    @IBAction func tapAlert(_ sender: Any) {
        //アラートを作る
        let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)

        //ボタン1
        alert.addAction(UIAlertAction(title: "追加する", style: .default, handler: nil))

        //ボタン2
        alert.addAction(UIAlertAction(title: "さらに追加する", style: .default, handler: nil))

        //消去する
        alert.addAction(UIAlertAction(title: "消去する", style: .destructive, handler: nil))

        //キャンセルボタン
        alert.addAction(UIAlertAction(title: "キャンセル", style: .cancel, handler: nil))

        //アラートを表示する
        self.present(alert, animated: true, completion: nil)
    }
}

以上です。
https://github.com/matushinn/AlertController

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2