Reputation: 29886
I have a UIbutton title that I set with
[[buttons objectAtIndex:selectedButtonTag] setTitle:file forState:UIControlStateNormal];
This for some reason doesnt force the button to change title.
When I print the title of the button with
UIButton *button = [buttons objectAtIndex:selectedButtonTag];
NSLog(@"button text is %@",button.titleLabel.text);
It actually prints the previously set title.
Is there some refresh call on the UI or why isnt the button displaying the title?
Upvotes: 2
Views: 1896
Reputation: 1030
Just so all of us don't have to google how to set background image :)
[myButton setBackgroundImage:[UIImage imageNamed:@"myImage.png"]
forState:UIControlStateNormal];
Upvotes: 0
Reputation: 51
You have to set the title of the button in Normal & Highlighted state also please make sure that image set to the button is set as its background image rather than image
Upvotes: 1
Reputation: 29886
To anyone having the same issue and has checked all other options. Make sure the png you use for the UIButton is set in the background image field, rather than the image field.
Upvotes: 6
Reputation: 57168
If you button is selected or highlighted and you've specifically set a title for one of those states, it will not show the UIControlStateNormal title.
If that's the case, I'd suggest either avoiding setting the title for anything other than the normal state, or else set the title for all potential states of your button.
Upvotes: 0