UIButton UIControlDefault标题值

时间:2012-10-24 07:40:27

标签: objective-c ios uibutton

需要检查IBOutLet UIButton *button是否没有写入文字。 要编码什么?

NSLog(@"%@", [button titleForState:UIControlStateNormal]);   //it gives (null)

我应该写决定声明吗?

2 个答案:

答案 0 :(得分:1)

确保您已设置UIControlState的标题,如下所示:

[button setTitle:@"Click Me!" forState:UIControlStateNormal];

否则,一切都应该正常工作。

<强>更新

要检查它是否没有文字,请使用:

if (![menuItemButton titleForState:UIControlStateNormal]) {
    NSLog(@"YES, no text.");
} else {
    NSLog(@"no, there is text.");
}

答案 1 :(得分:0)

最好检查button.labelTitle.text的长度。

感谢你们的答案。