tags:

views:

67

answers:

1

Is there any ground rule for using methods like drawRect, setNeedsDisplay and layoutSubViews? I believe they adversely affect the app performance. Is there any preferred alternatives for these messages?

A: 

While this isn't an exact duplicate of this question, I believe my answer there still applies.

In summary, -drawRect: will redraw the content within a view, which is an expensive operation. Avoid redrawing if you can by layering content and moving or hiding those layers as needed.

However, these redraws typically will only have a significant performance impact if there are many of them done in rapid succession, like when trying to animate content. One-off redraws of static UI elements will not perceptively slow things down.

Brad Larson
Thank you so much
Abhinav