gpt4 book ai didi

ios - 尝试加粗 UIButton 的 titleLabel 以响应在 iOS 中调用的委托(delegate)方法

转载 作者:可可西里 更新时间:2023-11-01 03:22:23 25 4
gpt4 key购买 nike

我正在开发一个调用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com