I have a UIView
and I set the constraints using Xcode Interface Builder.
Now I need to update that UIView's
height constant programmatically.
There is a function that goes like myUIView.updateConstraints()
, but I don't know how to use it.
I have a UIView
and I set the constraints using Xcode Interface Builder.
Now I need to update that UIView's
height constant programmatically.
There is a function that goes like myUIView.updateConstraints()
, but I don't know how to use it.
Drag the constraint into your VC as an IBOutlet. Then you can change its associated value (and other properties; check the documentation):
Select the height constraint from the Interface builder and take an outlet of it. So, when you want to change the height of the view you can use the below code.
Method
updateConstraints()
is an instance method ofUIView
. It is helpful when you are setting the constraints programmatically. It updates constraints for the view. For more detail click here.To update a layout constraint you only need to update the constant property and call layoutIfNeeded after.
Change
HeightConstraint
andWidthConstraint
Without creatingIBOutlet
.Note: Assign height or width constraint in Storyboard or XIB file. after fetching this Constraint using this extension.
You can use this extension to fetch a height and width Constraint
You can uses