美文网首页Swift学习记录
swift3.0 UIButton按钮创建

swift3.0 UIButton按钮创建

作者: 郑州程序员王一 | 来源:发表于2017-01-05 23:24 被阅读46次
    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按钮创建

        本文链接:https://www.haomeiwen.com/subject/qlktbttx.html