Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redraw customized UIButton after click

I have a customized UIButton that I want to redraw after it is clicked -- 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 there way to call drawRect again in my main thread?

like image 901
Liumx31 Avatar asked Feb 10 '23 15:02

Liumx31


1 Answers

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

like image 67
TwoStraws Avatar answered Feb 24 '23 18:02

TwoStraws