user4951
user4951

Reputation: 33070

Why Text Does Not Show Up for UIButton

UIImage *segmentSelected = [[UIImage imageNamed:@"Button_on"] resizableImageWithCapInsets2:UIEdgeInsetsMake(7, 7, 7, 7)];
UIImage *segmentUnselected = [[UIImage imageNamed:@"Button_off"] resizableImageWithCapInsets2:UIEdgeInsetsMake(7, 7,7,7)];

for (UIButton * button in @[self.catalog,self.business]) {
    [button setBackgroundImage:segmentSelected forState:UIControlStateSelected];
    [button setBackgroundImage:segmentUnselected forState:UIControlStateNormal];
}
self.business.selected=true;
[self.business setTitle:@"Business" forState:UIControlStateNormal];
[self.catalog setTitle:@"Catalog" forState:UIControlStateNormal];

The result is the text only show up when I press and hold the button. Not by default.

What's wrong?

Upvotes: 0

Views: 638

Answers (2)

user4951
user4951

Reputation: 33070

This has to be a bug.

Changing the text color to another color solve the problem. But I want white color. So what I did is there are 2 white box in the color.

The "default" white and the "white" white.

Change things to white white and voila it works.

Upvotes: 0

Neelam Verma
Neelam Verma

Reputation: 3274

set title for all states:

[self.business setTitle:@"Business" forState:UIControlStateNormal];
[self.catalog setTitle:@"Catalog" forState:UIControlStateNormal];
[self.business setTitle:@"Business" forState: UIControlStateHighlighted];
[self.catalog setTitle:@"Catalog" forState: UIControlStateHighlighted];
[self.business setTitle:@"Business" forState: UIControlStateSelected];
[self.catalog setTitle:@"Catalog" forState: UIControlStateSelected];

Work?

Upvotes: 2

Related Questions