设置颜色
btn.setTitleColor(UIColor.blackColor(),forState: .Normal)
设置点击事件
btn.addTarget(self, action: "btnClicked", forControlEvents: UIControlEvents.TouchUpInside)
设置背景图片
btn.setBackgroundImage(UIImage(named: “name”), forState: UIControlState.Normal)
自定义Button
import Foundation
import UIKit
class MyButton: UIButton
{
let img = "myButton"
required override init(frame: CGRect) {
super.init(frame: frame)
setBackgroundImage(UIImage(named: img), forState: UIControlState.Normal)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}