You should only call setNeedsDisplay if you override drawRect in a subclass of UIView, which is basically a custom view that draws something on the screen, such as lines, images, or shapes, such as a rectangle.
So, you must call setNeedsDisplay when you make changes to several variables that this drawing depends on, and to represent this change, you need to call this method, which internally will call drawRect and redraw the components.
When you add imageView or UIButton as a subtitle or make changes to any subtitle, you do not need to call this method.
Example:
You have a view showing a moving circle, either touching, or moving, or timer-based animations. Now for this you need a custom view that draws a circle in this center and with a given radius. They are saved as instance variables that change to move the circle, changing its center or increasing its radius.
Now in this case, either you will change these variables (in the center or in the radius) in the loop and timer. Or maybe your fingers are tapped and touched the simulated methods. To reflect the change in this property, you need to redraw this view for which you call setNeedsDisplay.
Amogh Talpallikar May 30 '12 at 2:32 pm 2012-05-30 14:32
source share