Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What are the problem?

すぐにアラートを作る為に (UIAlertController)

今回の内容

  • 3種類のアラートをすぐ作れる様にカスタム前の状態で、書き残しておきます。

コードと表示結果

アラート1(preferredStyle: .alert) 

BD3DDCDB-0A84-4DE4-BBCE-950795356A40_1_201_a.jpeg


        let usualAlert = {() -> UIAlertController in

            let alert = UIAlertController(title: "タイトルだよ", message: "アラートの内容だよ", preferredStyle: .alert)

            alert.addAction(UIAlertAction(title: "No", style: .destructive, handler: { _ in

                print("No")     
            }))

            alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: { _ in

                print("Yes")                
            }))

            return alert
        }()

        self.present(usualAler, animated: true, completion: nil)

アラート2(preferredStyle: .actionSheet) 

206C76A8-4522-4C54-BBBE-211E3F15A2DB_1_201_a.jpeg

        let usualActionSheetAlert = {() -> UIAlertController in

            let alert = UIAlertController(title: "タイトルだよ", message: "アラートの内容だよ", preferredStyle: .actionSheet)

            alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: { _ in

                print("Yes")                
            }))

            alert.addAction(UIAlertAction(title: "No", style: .destructive, handler: { _ in

                print("No")                
            }))

            alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { _ in

                print("cancel")                
            }))

            return alert
        }()

        self.present(usualActionSheetAlert, animated: true, completion: nil)

アラート3(preferredStyle: .alert) TextFieldを表示

DFCD3B9F-C6FD-4318-98FC-6CC2F60F588E_1_201_a.jpeg

        let textfieldInAlert = {() -> UIAlertController in

            let alert = UIAlertController(title: "タイトルだよ", message: "アラートの内容だよ", preferredStyle: .alert)

            alert.addTextField { (alertTextField:UITextField) in

                alertTextField.placeholder = "文字を入力してね"

            }

            alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: { _ in

                print("Yes")

            }))

            alert.addAction(UIAlertAction(title: "No", style: .destructive, handler: { _ in

                print("No")

            }))

            return alert
        }()

        self.present(textfieldInAlert, animated: true, completion: nil)

終わり

ご指摘、ご質問などありましたら、コメントまでお願い致します。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
0
Help us understand the problem. What are the problem?