Hi all,
I'm trying to use auto layout for the first time to position two UILabels with
variable height. I'd also like a 16px vertical gap between them. So I created
these constraints:
self.firstLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.secondLabel.translatesAutoresizingMaskIntoConstraints = NO;
NSLayoutConstraint *firstLabelHeight =
[NSLayoutConstraint constraintWithItem: self.firstLabel
attribute: NSLayoutAttributeHeight
relatedBy: NSLayoutRelationGreaterThanOrEqual
toItem: nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier: 0.0f
constant: 16.0f];
NSLayoutConstraint *secondLabelHeight =
[NSLayoutConstraint constraintWithItem: self.secondLabel
attribute: NSLayoutAttributeHeight
relatedBy: NSLayoutRelationGreaterThanOrEqual
toItem: nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier: 0.0f
constant: 16.0f];
NSLayoutConstraint *distance =
[NSLayoutConstraint constraintWithItem: self.secondLabel
attribute: NSLayoutAttributeTop
relatedBy: NSLayoutRelationEqual
toItem: self.firstLabel
attribute: NSLayoutAttributeBottom
multiplier: 0.0f
constant: 16.0f];
And then add them to the view:
[self.view addConstraints: @[firstLabelHeight, secondLabelHeight,
distance]];
The two labels change their heights based on the amount of text, which is good.
But they are not shown underneath each other, they both have the same
y-coordinate and are drawn over each other.
What am I missing here?
Thanks,
- Koen.
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]