简体   繁体   English

UIButton的标题消失了

[英]UIButton's title disappears

I added buttons to xib as normal using iOS 6 SDK and Xcode 4.5. 我通常使用iOS 6 SDK和Xcode 4.5向xib添加按钮。

When I run the app on iOS 6 simulator, there is no problem. 当我在iOS 6模拟器上运行该应用程序时,没有问题。 But when I run it on the iOS 5.x simulator (or device), the title on the button always disappears(not every time). 但是,当我在iOS 5.x模拟器(或设备)上运行它时,按钮上的标题总是消失(并非每次都消失)。 Lots of my view controllers have this problem. 我的许多视图控制器都有此问题。

在此处输入图片说明

PS: Only Custom type button have this problem PS:只有“自定义类型”按钮存在此问题

在此处输入图片说明

Found the reason: 发现原因:
[[UIButton appearanceWhenContainedIn:[UISearchBar class], nil] setTitle:@"取消" forState:UIControlStateNormal] [[UIButton外观WhenContainedIn:[UISearchBar类],无] setTitle:@“取消” forState:UIControlStateNormal]

Did you set the font title as Attributed which is not working with iOS 5 & iOS 5.1 ? 您是否将字体标题设置为Attributed ,这不适用于iOS 5和iOS 5.1? change it to Plain , now it should work fine with all versions. 将其更改为Plain ,现在它可以在所有版本上正常工作。

EDIT 编辑

when you select the button in your xib your attribute inspector should look like this: 当您选择xib的按钮时, attribute inspector应如下所示: 在此处输入图片说明

Make sure you are putting image in Background and not in Image (see image below) 确保将图像放置在Background而不是Image (请参见下图)

Also check if you are adding title using code, then [button setTitle:title forState:state]; 还要检查是否使用代码添加标题,然后[button setTitle:title forState:state]; should be there. 应该在那里。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM