i have many custom buttons, and i want to set a color for state selected and not selected.
this is my drawrect
override func drawRect(rect: CGRect) {
print("status = \(self.selected)")
if self.selected {
self.titleLabel?.textColor = UIColor(red: 255.0, green: 255.0, blue: 255.0, alpha: 1.0)
}else {
self.titleLabel?.textColor = UIColor(red: 166.0, green: 142.0, blue: 83.0, alpha: 1.0)
}
let path = UIBezierPath()
path.moveToPoint(CGPoint(x: self.bounds.minX, y: self.bounds.maxY))
path.addLineToPoint(CGPoint(x: self.bounds.maxX, y: self.bounds.maxY))
path.closePath()
// path.addLineToPoint(center)
UIColor.blackColor().setStroke()
path.lineWidth = 3.0
path.stroke()
}
private var isSelectedValue = false
var isThisButtonSelected : Bool {
get {
return isSelectedValue
}
set {
isSelectedValue = newValue
selected = newValue
switch newValue {
case true:
self.selected = true
rightImageView?.image = UIImage(named: "selection-preferences")
break;
case false:
self.selected = false
rightImageView?.image = nil
break;
}
}
}
i have many buttons, and as you see, i print the selected status.
the result is always false (as you will see in the screenshot)
my problem is that the color is white when not selected even though i say in the draw rect that if not select, make specific color
but it work good when i select a button so the color becomes white, as you see, but why when i unselect the color not change?
when the user click on the button, i do this in my view controller
@IBAction func foodTabled(sender: PreferenceButton) {
sender.isThisButtonSelected = !sender.isThisButtonSelected
}