Adding Constraints in Code
Adding Constraints in Code
- Subject: Adding Constraints in Code
- From: Dave <email@hidden>
- Date: Mon, 14 Sep 2015 10:35:12 +0100
Hi All,
I’m trying to add Constraints to a View in order to have it stretch to the left and right edges of the superview. This is slight complicated by it being in a ScrollView/Stack View Combo as so:
NSScrollView Setup in NIB
NSFlippedClipView Setup in NIB
NSStackView Setup in NIB
LTWDetailXView (added dynamically in code).
The Detail View is smaller in Width than the NSScrollView/NSStackView and I want it to stretch to fit it.
I tried adding the following constraints in code as follows:
myDetailView = [myDetailViewController getPrimaryView];
[self.pValidationListStackView addView:myDetailView inGravity:NSStackViewGravityTop];
myConstraintsViewDictionary = [[NSMutableDictionary alloc] init];
[myConstraintsViewDictionary setObject:self.pValidationListStackView forKey:@"StackView"];
[myConstraintsViewDictionary setObject:myDetailView forKey:@"DetailView"];
myConstraintsArray = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[StackView]-(<=1)-[DetailView]" options:NSLayoutFormatAlignAllLeft metrics:nil views:myConstraintsViewDictionary];
[myDetailView addConstraints:myConstraintsArray];
myConstraintsArray = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[StackView]-(<=1)-[DetailView]" options:NSLayoutFormatAlignAllRight metrics:nil views:myConstraintsViewDictionary];
[myDetailView addConstraints:myConstraintsArray];
But I get this Error Message:
Unable to parse constraint format:
Options mask required views to be aligned on a horizontal edge, which is not allowed for layout that is also horizontal.
H:[StackView]-(<=1)-[DetailView]
^
I’m not sure what this means or if the above code is correct?
If anyone has any ideas on this I’d really love to hear them!
Thanks a lot for any help.
All the Best
Dave
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden