ActionSheetの実装の仕方[Xcode/Storyboard]
4448 ワード
アプリを使っていると、カメラかアルバムを選択するシートをみたことがあるかと思います。
Xcode/Storyboardでどのように実装するかを簡単に実装して記事にしました。
環境
・Mac Book Pro(macOS:BigSur)
・Xcode(ver:12.5)
実装例
コード例
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)
}
}
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)
}
}
Author And Source
この問題について(ActionSheetの実装の仕方[Xcode/Storyboard]), 我々は、より多くの情報をここで見つけました https://qiita.com/swiftEnginnerY/items/10e3203b225b1fc3c58f著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .