Cocoa - iOS -Does updating the text property of a UILabel require setNeedsDisplay?

359 Views Asked by At

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

2

There are 2 best solutions below

2
smparkes On BEST ANSWER

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.

0
Laurent Crivello On

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]];