swift的UIbutton
override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let button:UIButton = UIButton(type:.custom) button.frame = CGRect(x:10, y:150, width:100, height:30) button.setTitle("按钮", for:.normal) button.backgroundColor=UIColor.blue button.setTitleColor(UIColor.white, for: .normal) button.addTarget(self, action:#selector(click), for:.touchUpInside) // button.addTarget(self, action:, for: .touchUpInside) self.view.addSubview(button) //self.view.addSubview(label) } @objc func click(btn:UIButton){ print("按钮呗点击了") btn.backgroundColor = UIColor.green }