Xcode9学习笔记31

来源:互联网 发布:锤子科技 知乎 编辑:程序博客网 时间:2024/05/16 01:15

    override func viewDidLoad() {        super.viewDidLoad()        // Do any additional setup after loading the view, typically from a nib.        let bt = UIButton(type: UIButtonType.system)        bt.frame = CGRect(x: 20, y: 120, width: 280, height: 44)        bt.setTitle("Question", for: UIControlState())        bt.addTarget(self, action: #selector(ViewController.showActionSheet), for: .touchUpInside)        bt.backgroundColor = UIColor.lightGray        self.view.addSubview(bt)    }        @objc func showActionSheet() {        let alert = UIAlertController(title: "Information", message: "What's your favorite", preferredStyle: UIAlertControllerStyle.actionSheet)//设置弹出窗口样式为动作表        let fishing = UIAlertAction(title: "Fishing", style: UIAlertActionStyle.default) { (alerts: UIAlertAction) in print("I like fishing")//默认样式的按钮        }        let hunting = UIAlertAction(title: "Hunting", style: UIAlertActionStyle.destructive) { (alerts: UIAlertAction) in print("I like hunting")//消除样式的按钮        }        let nothing = UIAlertAction(title: "Nothing", style: UIAlertActionStyle.cancel) { (alerts: UIAlertAction) in print("I like nothing")//取消样式的按钮        }        alert.addAction(fishing)        alert.addAction(hunting)        alert.addAction(nothing)        self.present(alert, animated: true, completion: nil)    }



原创粉丝点击