4.10 (底部弹窗) 动作表样式警告窗口的使用

企业微信截图_a4158715-4dec-46b6-8778-f2c36bdf14d1.png
    @objc func yeBtnClick()
    {   // 点击 Btn 触发方法:
        yeUIAlertCtrlActionSheet()
    }
    
    func yeUIAlertCtrlActionSheet()
    {
        //--- 1. 初始化控件 及其 显示的信息:
        let alert = UIAlertController(title: "Information", message: "What's your favorite?", preferredStyle: UIAlertController.Style.actionSheet) // .Style.actionSheet 的样式;
        
        
        //--- 2. 添加 弹窗上的Btn: (可添加多个Btn)
        // style: .default: Btn的文字是蓝色显示; style: .destructive: Btn的文字是红色显示;
        // style: .cancel: 的Btn 只能有一个;(.default和.destructive 都可以有多个)
        let eBtn1 = UIAlertAction(title: "Btn1-Fishing", style: .default, handler: {(alerts: UIAlertAction) -> Void in
            print("I like fishing")
        })
        alert.addAction(eBtn1)

        let eBtn2 = UIAlertAction(title: "Btn2-Hunting", style: .default, handler: {(alerts: UIAlertAction) -> Void in
            print("I like hunting")
        })
        alert.addAction(eBtn2)

        // 2.3 style: .destructive: Btn的文字是红色显示;
        let eBtn3 = UIAlertAction(title: "Btn3-Nothing", style: .destructive, handler: {(alerts: UIAlertAction) -> Void in
            print("Btn3 -A Life of Nonsense.")
        })
        alert.addAction(eBtn3)

        // 2.4: cancel Btn:
        let eBtnCancel = UIAlertAction(title: "Btn4-Nothing", style: .cancel, handler: {(alerts: UIAlertAction) -> Void in
            print("BtnCancel- A Life of Nonsense.")
        })
        alert.addAction(eBtnCancel)

        
        //--- 3. 弹窗 UIAlertCtrl 消息窗口;
        self.present(alert, animated: true, completion: nil) //(模态的形式)弹窗 UIAlertCtrl 消息窗口;
    }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容