0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ActionSheetの実装の仕方[Xcode/Storyboard]

Posted at

アプリを使っていると、カメラかアルバムを選択するシートをみたことがあるかと思います。
Xcode/Storyboardでどのように実装するかを簡単に実装して記事にしました。

#環境
・Mac Book Pro(macOS:BigSur)
・Xcode(ver:12.5)

#実装例
Unknown-2.gif

#コード例

ViewController.swift
class ViewController: UIViewController {

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


    @IBAction func showAlert(_ sender: Any) {
        
        let alertController = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .actionSheet)
        
        let action1 = UIAlertAction(title: "タイトル1", style: .default) { alert in
            print("Action1")
        }
        
        let action2 = UIAlertAction(title: "タイトル2", style: .default) { (alert) in
            print("Action2")
        }
        
        let action3 = UIAlertAction(title: "キャンセル", style: .cancel, handler: nil)
        
        alertController.addAction(action1)
        alertController.addAction(action2)
        alertController.addAction(action3)
        self.present(alertController, animated: true, completion: nil)
    }
}
0
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?