I have a problem to setting the constraints of a custom uiview which is loaded from nib and added as subview to a containerview. I'm trying to add the constraints in the willMove(toSuperView)
method but it's not working as expected. Where is the most appropriate place to set constraints of a custom UIView
?
Heres the code;
extension ErrorView {
override func willMove(toSuperview newSuperview: UIView?) {
super.willMove(toSuperview: newSuperview)
guard let newSuperview = newSuperview else { return }
translatesAutoresizingMaskIntoConstraints = false
newSuperview.setConstraintHeight(to: self)
SetConstraintWidth(to: newSuperview)
}
}
the setConstraintWidth
and setConstraintHeight
method names are placeholders. You can think as they are methods to setting the constraints.