I'm trying to understand when to override layoutSubviews
versus updateConstraints
.
I have created a custom view, and that view contains other views. I can't set the constraints for the view's subviews in the custom initializer I have as I don't know the custom view's frame yet.
Currently I have this:
-(void)layoutSubviews
{
[super layoutSubviews];
// Add new constraints
}
Then whenever I add or remove any of the subviews, I call [self setNeedsLayout];
Is this the correct way to do this? I am currently recreating the constraints whenever layoutSubviews
is called. I've heard that updateConstraints
might be what I want? But I'm not sure as the number of subviews does not remain constant, and thus, the number of constraints will not be constant either.