Search code examples
iosobjective-cuibuttontextcolor

How to check the colour of the text on a UIButton?


Sounds simple, right? Well I've Googled over a dozen search strings and still cannot find the answer.

To set the colour we implement the following code:

[_myUIButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];

But what about testing to see what the colour is of the text of the button??? Surely this is possible to do, right?

Shouldn't the code be something like this:

if([_myUIButton.textColor isEqual:[UIColor blueColor]])
{
    // then true
}

This code won't work with the button title text colour, but someone must know how it can be done.

Please help.


Solution

  • if([button titleColorForState:UIControlStateNormal] isEqual:[UIColor blackColor]]){
    
      }