Cocoa - iOS - 更新 UILabel 的文本属性是否需要 setNeedsDisplay?
我是一个新手,我有一个 iOS 项目,我正在其中设置 UILabel 字段的文本属性。
self.nameLabel.text = @"abcd";
问题
- 我是否需要为要显示的新文本值的标签调用 setNeedsDisplayInRect ?
我的理解基于一些测试:
- 在不调用 setNeedsDisplayInRect 的情况下,标签的文本已更新,
- 但我想知道这是巧合还是保证标签将在不显式调用的情况下显示新值设置需求显示
谢谢
I am a newbie and I have a iOS project where I am setting the text property of a UILabel field.
self.nameLabel.text = @"abcd";
Question
- Do I need to invoke setNeedsDisplayInRect for the label for the new text value to be displayed ?
My understanding based on some testing:
- Without invoking setNeedsDisplayInRect, the the label's text was updated,
- but I want to know if it was a coincidence or is gauranteed that the the label will display the new value without explicitly invoking setNeedsDisplay
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您设置其
text
属性时,UILabel
将执行更新所需的所有操作。其他属性(font
、textColor
等)也是如此。您唯一需要手动执行的操作(如果您不使用 IB)就是设置框架。
A
UILabel
will do everything needed for updates when you set itstext
property. Same for its other properties (font
,textColor
, etc.) About the only thing you have to do manually (if you're not using IB) is set theframe
.如果文本更新后标签没有刷新,则您的 CPU 可能已被充分利用,并且以下命令将强制刷新:
If the label does not refresh despite the text update, your CPU may be fully utilized and the following command will force the refresh: