I am subclassing UIButton.
But I need to know the state that the button is in to draw the color of button for up or down:
- (void)drawRect:(CGRect)rect{
if (state==UIControlStateNormal) {
//draw rect RED
}
if (state==UIControlEventTouchDown)
//draw rect BLUE
}
}
Did you even try looking at the docs?
UIButtonhas a superclassUIButton‘s superclassstatepropertyUpdate
The accepted answer is slightly incorrect and could lead to some annoyingly difficult bug to track down.
The header for
UIControldeclaresstateasNow looking up to see how
UIControlStateis defined we seeTherefore as you are dealing with a bit mask you should check for the state appropriately e.g.
Update 2
You could do this by drawing into an image and then setting the image as the background e.g.