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)")
}
Swift中UIButton写法
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 我相信大家从OC转到Swift的时候总会有这个困惑“以前在OC这样用,Swift该怎么写?多的不说了往下看。 1....
- Swift中类方法class func customizedNavigationController() -> U...
- var attributedString = NSMutableAttributedString(string:"...