Reputation: 26952
I've got an autolayout constraint that attaches a view just above the tab bar. The specifics of this aren't important, it works fine.
NSDictionary *views = @{@"view":self.collectionSelectionContainer, @"bottomLayoutGuide":self.bottomLayoutGuide};
NSDictionary *metrics = @{@"offset":@(tabBarHeight)};
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[view]-offset-[bottomLayoutGuide]" options:0 metrics:metrics views:views]];
However, I want to create this constraint using the other method:
[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]
I've tried various ways unsuccessfully. Can anybody show me how?
Thanks
Upvotes: 1
Views: 2033
Reputation: 26952
I figured that I could just inspect the NSLayoutConstraint returned array from constraintsWithVisualFormat! This actually was a great way to figure it out and then build the method from there:
The answer is this:
self.collectionSelectionBottomConstraint = [NSLayoutConstraint constraintWithItem:self.bottomLayoutGuide attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.collectionSelectionContainer attribute:NSLayoutAttributeBottom multiplier:1 constant:tabBarHeight];
[self.view addConstraint:self.collectionSelectionBottomConstraint];
I think the reason I was being unsuccessful before was that I was passing 0 as the multiplier.
Upvotes: 2