Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

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

share|improve this question
    
Hey mate, out of interest why aren't you connecting the bottom of 'collectionSelectionContainer' to the top of the 'tabBar' ? – Mike Pollard Sep 3 '13 at 16:19
    
Ey up Mike.... My layout constraints are in a view controller that is in a containment hierarchy. So attempting to add the constraint to the tab bar, which isn't a descendant of my view, violates the rules. – bandejapaisa Sep 3 '13 at 18:09
    
Ah, sounds complicated ... sure beats setting frames though eh! :) – Mike Pollard Sep 4 '13 at 8:41

1 Answer 1

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.

share|improve this answer
    
I had to use Top instead of TopMargin. That was the error in my case. – testing Oct 10 '14 at 12:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.