UIButton's title disappears

I added buttons to xib as normal using iOS 6 SDK and Xcode 4.5.

When I run the app on iOS 6 simulator, there is no problem. But when I run it on the iOS 5.x simulator (or device), the title on the button always disappears(not every time). Lots of my view controllers have this problem.

在这里输入图像描述

PS: Only Custom type button have this problem

在这里输入图像描述

Found the reason:
[[UIButton appearanceWhenContainedIn:[UISearchBar class], nil] setTitle:@"取消" forState:UIControlStateNormal]


Did you set the font title as Attributed which is not working with iOS 5 & iOS 5.1 ? change it to Plain , now it should work fine with all versions.

EDIT

when you select the button in your xib your attribute inspector should look like this: 在这里输入图像描述


Make sure you are putting image in Background and not in Image (see image below)

Also check if you are adding title using code, then [button setTitle:title forState:state]; should be there.

在这里输入图像描述

链接地址: http://www.djcxy.com/p/96252.html

上一篇: UIButton - 什么是默认图像高亮颜色

下一篇: UIButton的标题消失