rPragma rPragma - 6 months ago 28
Swift Question

iOS: Callback of 'When all subviews have been added' for a UIView

I am creating a custom view by overriding a

UIVIew
class in Swift.

And in
init?(coder: NSCoder)
,
subviews.count
is zero, while
didAddSubview(subview: UIView)
is called only for direct children.

Is there any callback, when all of the children (even children of child) have been added to the view ?

Or, is there any callback that is called after the view is 'loaded from storyboard' and all of the subviews have been laid out to the view, so that
subviews.count
is not zero ?

Answer

and all of the subviews have been laid out to the view

That would be layoutSubviews. Be sure to call super. If you want to do this only the first time, use a flag.