今天要介紹第二個按鈕元件,是帶圓角的,程式碼如下:
class CustomButton: UIButton {
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
setButton()
}
override func awakeFromNib() {
setButton()
}
func setButton(){
self.setTitleColor(#colorLiteral(red:1, green: 1, blue: 1, alpha: 1), for: .normal)
self.layer.cornerRadius = self.bounds.height / 2
self.backgroundColor = UIColor(red:136/255 , green: 217/255, blue: 159/255, alpha: 1)
self.layer.borderWidth = 0
self.titleLabel?.font = UIFont(name: "System", size: 13)
}
}
成果: