为什么不能通过点语法更改UIButton文本? [英] Why does not work changing UIButton text via dot syntax?
本文介绍了为什么不能通过点语法更改UIButton文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以通过点语法更改UIButton标题标签文本?如果通过点语法进行操作,文本不会更改:
Is it possible to change UIButton title label text via dot syntax? The text is not changing if I do it via dot syntax:
self.myButton.titleLabel.text = [NSString stringWithString:@"Nop"];
但是这确实做到了:
[self.myButton setTitle: @"Yep" forState: UIControlStateNormal];
文本更改仅适用于纯UILabel,UIButton是特殊情况还是其他原因?
Text change works for pure UILabels, is UIButton a special case or something?
推荐答案
这是因为可以将UIButton的文本更改为几种不同的状态(正常",突出显示"等).苹果只是选择要求使用显式代码来设置文本.如果确实需要,您可以创建一个类别来实现此目的.
This is because the text can be changed for a UIButton for several different states (Normal, Highlighted, etc). Apple simply chose to require explicit code to set the text. You could probably create a category to implement this, if you really wanted.
这篇关于为什么不能通过点语法更改UIButton文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文