Redraw custom UIButton after click

I have a custom UIButton that I want to redraw after clicking it - I want to change its color. Here is the code:

class DayButtons: UIButton {

    var isPressed: Bool = false

    var color = UIColor.whiteColor()

        override func drawRect(rect: CGRect) {
        let cornerR = CGFloat(5)       
        var path = UIBezierPath(roundedRect: rect, cornerRadius: cornerR)
        color.setFill()
        path.fill()
    }
}

Is it possible to call drawRect in my main thread again?

+4
source share
1 answer

You should call setNeedsDisplay()on your button, which in turn will call for you drawRect().

+7
source

All Articles