2018-08-22 Swift set UIButton

Swift4.0一些改变

func bt () {

     let bt = UIButton()

     let rect = CGRect(x: 100, y: 100, width: 100, height: 40) 

     bt.frame = rect bt.setTitle("按钮", for: UIControlState.normal) 

     bt.setTitleColor(UIColor.red, for: UIControlState.normal) 

     let sel = #selector(btClick(_:)) 

     bt.addTarget(self, action:sel, for: UIControlEvents.touchUpInside)                

    view.addSubview(bt) 

 } 

 @objc func btClick(_ bt:UIButton) { 

        print("btClick()") 

 }


你可能感兴趣的:(2018-08-22 Swift set UIButton)