UIButton初始化
let testButton:UIButton = UIButton(type: .Custom)
//UIButtonType:Custom System DetailDisclosure InfoLight InfoDark ContactAdd RoundedRect
testButton.frame = CGRect(x: 100, y: 100, width: 100, height: 100)
設(shè)置背景色
testButton.backgroundColor = UIColor.redColor()
狀態(tài)設(shè)置
//UIControlState:Normal Highlighted Disabled Selected
testButton.setTitle("normal", forState: .Normal)
testButton.setTitle("highlighted", forState: .Highlighted)
testButton.setTitleColor(UIColor.blackColor(), forState: .Normal)
testButton.setTitleColor(UIColor.yellowColor(), forState: .Highlighted)
圖片設(shè)置
testButton.setImage(UIImage(named: "imageName"), forState: .Normal)
字體設(shè)置
testButton.titleLabel?.font = UIFont.systemFontOfSize(12)
點擊事件
testButton.addTarget(self, action:#selector(testButtonClick(_:)) , forControlEvents: UIControlEvents.TouchUpInside)
點擊方法實現(xiàn)
func testButtonClick(btn:UIButton) -> Void {
print("click")
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者