iOS: Programmatically change height constraint of a UIView
First add height constraint to your .h
file:
//Add Outlet IBOutlet NSLayoutConstraint *ViewHeightConstraint;
Next, add the below code to your .m
file:
//Set Value From Here ViewHeightConstraint.constant = 100;
You can connect that specific constraint to your code from the interface builder like
And NSLayoutConstraint
has a constant property to be set which is your constant pin value.
If you're adding your constraints programmatically, you can surely benefit from the identifier property in NSLayoutConstraint
class. Set them and iterate over them to get that specific identifired constraint.
As the documentation says
extension NSLayoutConstraint { /* For ease in debugging, name a constraint by setting its identifier, which will be printed in the constraint's description. Identifiers starting with UI and NS are reserved by the system. */ @availability(iOS, introduced=7.0) var identifier: String?}