Reputation: 77
One issue i am facing related to autolayouts. I am setting height of view containing image views to zero first via autolayouts. But if certain function is called I want that height updated to a constant value, but height of my view is not getting updated. Here is the code, i have updated height programmatically inside the function but it is not working.
let heightContraint = NSLayoutConstraint(item: businessImageView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 40)
businessImageView.addConstraint(heightContraint)
Upvotes: 0
Views: 7420
Reputation: 29
// lets detect the height of our screen here
int height = [UIScreen mainScreen].bounds.size.height;
int width = [UIS
creen mainScreen].bounds.size.width;
// share the news
NSString *message = [[NSString alloc]initWithFormat:@"This screen is \n\n%i pixels high and\n%i pixels wide", height, width];
NSLog(@"%@", message);
Upvotes: 0
Reputation: 17685
heightConstraint.isActive = true
heightConstraint.constant = 20
Upvotes: 0
Reputation: 14113
businessImageView.addConstraint(heightContraint)
is not the code to update the constraint. It adds a constraint.
So as to update the height of parent view (which has images), you would need to update the constant for businessImageView's height constraint.
businessImageView.heightConstraint.constant = 40
self.view.layoutIfNeeded()
Upvotes: 0
Reputation: 749
First create IBOutlet of the height constraint.
You just need to change constant
property of the constraint.
For e.g.:
self.consTblFilterHeight.constant = 100.0
self.view.layoutIfNeeded()
Replace self.view
with the parent view of the view you are changing the height.
Upvotes: 3
Reputation: 1493
Create your constraint outlet and then set it like this :
Upvotes: 1