1

I am trying to use auto layout in x code to correctly resize my view to switch between iphone 4 and 5.

I have a similar problem as the one presented in the picture. Let's consider the UILabel at the bottom is fixed. I want the top UILabel to be at the middle of the space between the navigation bar and the bottom label. I don't know how to add a constraint that says "top space and bottom space must be equal". As a result, I can only fix one of the two constraints and I cannot get the expected result.

Thanks

On the iPhone 5 screen, my top UILabel is not vertically centered.

Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
Gabriel
  • 2,331
  • 2
  • 13
  • 18
  • Does this answer help? It's a little more complicated situation, but I think the same principles are involved: http://stackoverflow.com/questions/19327095/xcode-5-autolayout-equal-distribution-of-6-views – godel9 Oct 24 '13 at 03:40
  • Thanks, I will have a lot. I put the label in a view, it works great. – Gabriel Oct 24 '13 at 06:01

2 Answers2

1

The way I do this in IB, is to embed the top label in a UIView. Give that view a standard vertical spacing constraint to the top layout guide, and another to the bottom label. Also give it a fixed width. Give the label centerX and centerY constraints to this view, and it should keep it centered in different screen sizes.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
1

How about adding a container view that fills up the space between the 1st label and the navigation bar, and then center the 2nd label inside the container view.

Khanh Nguyen
  • 11,112
  • 10
  • 52
  • 65
  • I have never used container view, so I use a simple view and put the label inside. It works great. Thank you for your answer. – Gabriel Oct 24 '13 at 06:01