some_id
some_id

Reputation: 29886

UIButton wont show title

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

Answers (4)

Yanchi
Yanchi

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

Arti
Arti

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

some_id
some_id

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

Jesse Rusak
Jesse Rusak

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

Related Questions