我正在开发一个调用 UITextFieldDelegate 方法的应用程序:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { }
我成功地调用了它,并且在该方法中,我启用了一个特定的按钮。这也很好用。但是,我面临的问题是启用按钮后我无法将按钮上的标题设为粗体。我在 Interface Builder 中设置了字体,并试图以编程方式将标题加粗。这是显示我在做什么的相关代码:
if ([keys count] == [_tireName count]) {
[_doneButton setEnabled:YES];//this line works
[[_doneButton titleLabel] setFont:[UIFont boldSystemFontOfSize:28]];//this line does nothing
} else if ([keys count] < [_tireName count]){
[_doneButton setEnabled:NO];//this line works
[[_doneButton titleLabel] setFont:[UIFont systemFontOfSize:28]];//this line does nothing
}
忽略“if”子句本身。我希望按钮启用时按钮上的文本为粗体,我希望按钮上的文本在禁用时为“正常”。我做错了什么?
最佳答案
如果您使用的是标准字体并希望将其设为粗体,这会更简洁:
[_doneButton.titleLabel setFont:[UIFont boldSystemFontOfSize:[UIFont systemFontSize]]];
这样,您就不必担心字体系列或大小。
关于ios - 尝试加粗 UIButton 的 titleLabel 以响应在 iOS 中调用的委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18836941/