Gabriel
Gabriel

Reputation: 2461

Resize proportionnaly between iphone 4 and 5 screens with XCode

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.

Upvotes: 1

Views: 1398

Answers (2)

Khanh Nguyen
Khanh Nguyen

Reputation: 11134

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.

Upvotes: 1

rdelmar
rdelmar

Reputation: 104082

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.

Upvotes: 1

Related Questions