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.
First connect the Height constraint in to our viewcontroller for creating IBOutlet like the below code shown
then put the below code in view did load or inside any actions
if it is inside a button click
If you have a view with multiple constrains, a much easier way without having to create multiple outlets would be:
In interface builder, give each constraint you wish to modify an identifier:
Then in code you can modify multiple constraints like so:
You can give multiple constrains the same identifier thus allowing you to group together constrains and modify all at once.
If the above method does not work then make sure you update it in Dispatch.main.async{} block. You do not need to call layoutIfNeeded() method then.