Daily iOS
UIKit

Layout update methods

What do setNeedsLayout and layoutIfNeeded each do in UIKit, and when should you call them?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

setNeedsLayout schedules layout for the next run loop, layoutIfNeeded runs the pending layout synchronously, right now, layoutSubviews is where the system actually places views, and setNeedsDisplay schedules draw(_:) to run again.

Share a question