swift3.0 UIButton按钮创建

override func viewDidLoad() {
        super.viewDidLoad()
        //按钮
        let btn = UIButton()
        btn.frame = CGRect(x: 10, y: 100, width: 200, height: 30)
        btn.setTitle("我的第一个APP", for: .normal)
        btn.backgroundColor = UIColor.red
        btn.titleLabel?.textColor = UIColor.white
        btn.layer.cornerRadius = 5
        btn.layer.masksToBounds = true
        btn.addTarget(self, action: #selector(ViewController.clickBtn), for: .touchUpInside)
        view.addSubview(btn)
        
    }
    
    func clickBtn(){
        let alert = UIAlertController(title: "提示", message: "我的第一个APP", preferredStyle: .alert)
        let btn = UIAlertAction(title: "明白", style: .default, handler: nil)
        alert.addAction(btn)
        self.present(alert, animated: true, completion: nil)
    }

你可能感兴趣的:(swift3.0 UIButton按钮创建)