为什么文本不显示UIButton

时间:2013-01-22 12:21:15

标签: objective-c 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];

结果是文本仅在我按住按钮时显示。不是默认的。

怎么了?

2 个答案:

答案 0 :(得分:2)

为所有州设置标题:

[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];

工作?

答案 1 :(得分:0)

这必须是一个错误。

将文本颜色更改为其他颜色可解决问题。但我想要白色。所以我所做的就是有2个白色的盒子。

“默认”白色和“白色”白色。

将东西变成白色白色,然后就可以了。