-1

When I do something on UIKit, I really want to ask a question.

when do I have to call setNeedsDisplay and when setNeedLayout?

Bo A
  • 3,144
  • 2
  • 33
  • 49
chroww
  • 183
  • 1
  • 4

3 Answers3

3

Calling setNeedDisplay forces the iOS to redraw. setNeedLayout forces layoutSubviews method to be called before next redraw.

Vignesh
  • 10,205
  • 2
  • 35
  • 73
0

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.

Amar
  • 13,202
  • 7
  • 53
  • 71
Manthan
  • 3,856
  • 1
  • 27
  • 58
-1

In simple terms

setNeedsDisplay : To redraw your view setNeedsLayout : To adjust positioning/sizing of your view

Niru Mukund Shah
  • 4,637
  • 2
  • 20
  • 34