LoginSignup
1
1

More than 3 years have passed since last update.

AlertViewを表示する(ダイアログ的なやつ)

Posted at

ボタンを押した時に下から出てくるやつを表示するコード

スクリーンショット 2020-03-29 18.42.23.png

スクリーンショット 2020-03-29 18.42.31.png

ViewController.swift

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    private func popUp() {
        let alertController = UIAlertController(title: "確認", message: "本当に実行しますか", preferredStyle: .actionSheet)

        let yesAction = UIAlertAction(title: "はい", style: .default, handler: nil)
        alertController.addAction(yesAction)

        let noAction = UIAlertAction(title: "いいえ", style: .default, handler: nil)
        alertController.addAction(noAction)

        let cancelAction = UIAlertAction(title: "キャンセル", style: .cancel, handler: nil)
        alertController.addAction(cancelAction)

        present(alertController, animated: true, completion: nil)
    }

    @IBAction func doButtonTap(_ sender: Any) {
        popUp()
    }
}

豆知識

comd + shift + l(エル)
でlibraryを表示できる。

1
1
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
1
1