1

I have a UIView on my UIViewController. I set width and height using Editor -> Pin -> Width/Height. Also i created IBOutlet of these constraints to change widht and height programatically. I worte code

in .h file

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *viewWidth;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *viewHeight;

in .m file

self.viewWidth.constant = 480;
self.viewHeight.constant = 644;

but still its not changing the width and height of view. Am i missing something? Thanks in advance.

paulmelnikow
  • 16,470
  • 7
  • 60
  • 112
Ameet Dhas
  • 2,440
  • 4
  • 23
  • 38

2 Answers2

0

After updating the constants, you need to invoke -layoutIfNeeded or -setNeedsUpdateConstraints.

paulmelnikow
  • 16,470
  • 7
  • 60
  • 112
0

Here a solution to update constants of constraints programmatically without IBOutlet.

Hide autolayout UIView : How to get existing NSLayoutConstraint to update this one

Community
  • 1
  • 1
Damien Romito
  • 9,262
  • 8
  • 62
  • 75