UIButton的选定状态不适用于iOS7

Noo*_*yed 2 iphone xcode objective-c uibutton ios

我正在使用Xcode 5的故事板来创建一个应用程序iOS SDK 7.0.

我拖了一个按钮到视图.我希望我的按钮默认显示"A".以下是按钮属性:类型:系统,状态配置:默认,标题:普通

我希望我的按钮在选定状态下显示"B".因此,更改的按钮属性:State Config:Selected

在Button的属性检查器中,在Control下,有一个名为Selected的属性.如果我选中选中,而不是显示"B",它只是像A上的标记一样突出显示,即没有看到任何字符.

I ran it in XCODE. WHen the button is not selected "A" is displayed as expected but when I select the button, instead of displaying B, the text portion of the button is highlighted with light blue color. Also, I never selected the Highlighted Content under the Control.

How can this be resolved, so that I can display the state correctly?

Chr*_*hen 6

对于通过代码设置按钮标题的任何人,我发现在iOS 7.1上,您需要为各种按钮状态显式设置标题,而在iOS 7.0上,为UIControlStateNormal设置标题也适用于其他按钮状态.

// works on 7.0
[self.ibActionButton setTitle:NSLocalizedString(@"Register", nil) forState:UIControlStateNormal];

// works on 7.1
[self.ibActionButton setTitle:NSLocalizedString(@"Register", nil) forState:UIControlStateNormal|UIControlStateDisabled];
Run Code Online (Sandbox Code Playgroud)


Jon*_*ast 5

在故事板中将State Config设置为Selected时,需要将按钮的标题设置为'B' .然后,您需要将操作连接到按钮的Touch Up Inside事件.在该操作内部,切换按钮的属性.selected

当您在"属性"检查器下选中"已选择"时,您只需将按钮的初始选择状态设置为"是".XCode还会显示该状态下按钮的外观.