override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let testBtn:UIButton = UIButton(type: .custom)
testBtn.frame = CGRect(x: 0, y: 600, width: 200.0, height: 30.0)
testBtn.setTitle("登陆", for: .normal)
testBtn.setTitleColor(UIColor.lightGray, for: .normal)
testBtn.tag = 101
//
testBtn.addTarget(self, action: #selector(testActionMethod), for: .touchUpInside)
// 带参数的按钮点击事件
// testBtn.addTarget(self, action: #selector(testAction(testBtn:)), for: .touchUpInside)
self.view.addSubview(testBtn)
}
@objc func testActionMethod(){
print("no arguments.....")
}
@objc func testAction(testBtn:UIButton){
print("testAction.... \(testBtn.tag)")
}
网友评论