import UIKit
class UIRadioButton: UIButton {
private var ischeck = false
override init(frame: CGRect) {
super.init(frame: frame)
self.layer.borderColor = UIColor(red: 255/255, green: 110/255, blue: 2/255, alpha: 1).CGColor;
self.layer.borderWidth = 1;
self.layer.cornerRadius = 8;
self.setTextColor(UIColor(red: 255/255, green: 110/255, blue: 2/255, alpha: 1))
self.setTextFont(14)
self.addTarget(self,action:Selector("tapped:"),forControlEvents:UIControlEvents.TouchUpInside)
}
//设置字体颜色
func setTextColor(color: UIColor){
self.setTitleColor(color, forState: .Normal)
}
//设置字体大小
func setTextFont(size:CGFloat){
self.titleLabel!.font = UIFont.systemFontOfSize(size)
}
//设置字体内容
func setText(title:String){
self.setTitle(title, forState: UIControlState.Normal)
}
//点击事件处理
func tapped(button:UIButton){
if(isCheck()){
setCheck(false)
}else{
setCheck(true)
}
}
//通过点击 改变背景
func setCheck(isCheck:Bool){
ischeck = isCheck
if(isCheck){
self.backgroundColor = UIColor(red: 255/255, green: 110/255, blue: 2/255, alpha: 1)
self.setTextColor(UIColor.whiteColor())
}else{
self.backgroundColor = UIColor.whiteColor()
self.setTextColor(UIColor(red: 255/255, green: 110/255, blue: 2/255, alpha: 1))
}
}
func isCheck()->Bool{
return ischeck
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}