positioning two UILabels with auto layout problem
positioning two UILabels with auto layout problem
- Subject: positioning two UILabels with auto layout problem
- From: Koen van der Drift <email@hidden>
- Date: Wed, 19 Jun 2013 17:41:00 -0400
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@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