How listen for UIButton state change?

Posted by morticae on Stack Overflow See other posts from Stack Overflow or by morticae
Published on 2010-03-23T21:21:29Z Indexed on 2010/03/23 21:23 UTC
Read the original article Hit count: 462

Filed under:
|
|
|
|

I'm extending UIButton with generic functionality to change certain appearance attributes based on the displayed title.

In order to do this, I need to detect and respond to changes in the "state" property. This is so I make sure the appearance is adjusted properly if the user has set different titles for different states. I assumed I would need to use some sort of KVO like the following:

[self addObserver:self forKeyPath:@"state" options:NSKeyValueObservingOptionNew context:nil];

But this does not seem to fire the observeValueForKeyPath:... method for @"state" or @"currentTitle". I assume this is because UIButton does not implement the KVO pattern for those properties.

I do not want to just listen for clicks. Those events cause a state change, but are not the only potential causes.

Does anyone know a way to listen to and respond to state changes of a UIButton?

Thanks

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about uibutton