1

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

4

2 回答 2

1

A UILabel will do everything needed for updates when you set its text 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 the frame.

于 2012-02-23T20:32:34.463 回答
0

If the label does not refresh despite the text update, your CPU may be fully utilized and the following command will force the refresh:

self.nameLabel.text = @"abcd";
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
于 2016-04-06T15:03:34.233 回答