When I do something on UIKit, I really want to ask a question.
when do I have to call setNeedsDisplay and when setNeedLayout?
When I do something on UIKit, I really want to ask a question.
when do I have to call setNeedsDisplay and when setNeedLayout?
Calling setNeedDisplay forces the iOS to redraw. setNeedLayout forces layoutSubviews method to be called before next redraw.
You can check the Apple Documentation for this.
setNeedsLayout will layout subviews
Call this method on your application’s main thread when you want to adjust the layout of a view’s subviews.
setNeedsDisplay will call for a redraw of your view (drawRect:, etc).
You can use this method or the setNeedsDisplayInRect: to notify the system that your view’s contents need to be redrawn.
In simple terms
setNeedsDisplay : To redraw your view setNeedsLayout : To adjust positioning/sizing of your view