Arnaud
Arnaud

Reputation: 17822

Auto layout constraints - Vertical spacing with one item of variable height

I have 2 UILabels above 2 UITextFields. I would like the first UITextField to expand when the screen size allows it.

I set vertical spacings between each elements, and fixed height constraint for the UITextField at the bottom and a >= height constraint for the first one.

Below is a screenshot with what it looks like with the retina 3.5 form factor (<= iPhone 4).

enter image description here

But, it just doesn't work. Below is a screenshot of the storyboard with the retina 4 form factor (>= iPhone 5). The first UITextField overlaps the second one.

What constraints should I set ?

enter image description here

Upvotes: 0

Views: 4351

Answers (2)

paulrehkugler
paulrehkugler

Reputation: 3271

The orange (-78) is Xcode's way of telling you you have a conflict between the frames of your layout and the autolayout constraints. Try looking at the storyboard warnings and fix the frame or fix the layout constraint.

Upvotes: 2

bandejapaisa
bandejapaisa

Reputation: 26972

If i had it in front of me I'd play around with the compression resistance properties, which would be more elegant than fixed heights... however....a crude way of doing it that would work is:

  1. You could have fixed height labels.
  2. Fixed height bottom text view.
  3. Pin the top text view to the bottom of the label. Pin the top label to the top of view.
  4. Pin the bottom text view to the bottom of the view, pin it's label above it.
  5. Pin the bottom of the top text view to the label below it.

Upvotes: 2

Related Questions