Contents

layoutSubviews()

Lays out subviews.

Declaration

func layoutSubviews()

Mentioned in

Discussion

The default implementation uses any constraints you set to determine the size and position of any subviews.

Subclasses can override this method as needed to perform more precise layout of their subviews. You should override this method only if the autoresizing and constraint-based behaviors of the subviews don’t offer the behavior you want. You can use your implementation to set the frame rectangles of your subviews directly.

Don’t call this method directly. If you want to force a layout update, call the setNeedsLayout() method instead to do so prior to the next drawing update. If you want to update the layout of your views immediately, call the layoutIfNeeded() method.

In iOS 18 and later, UIKit supports automatic trait tracking inside this method for traits from this view’s traitCollection. For more information, see Automatic trait tracking.

This method supports automatic observation tracking. For more information, see Updating views automatically with observation tracking.

See Also

Observing data in views