5
votes

I am using Xcode 4.5 and iPhone 4 and 5 simulator, and the Interface Builder would add a UIButton in the top half of the screen with a top constraint, and add a UIButton in the bottom half of the screen with a bottom constraint.

It works fine on an iPhone 5 simulator, but on the iPhone 4 simulator, the buttons can overlap, or the bottom button may even get positioned above the top button.

I think it is due to the constraint, such as the bottom button "must be 250 points away from the bottom margin". I can't delete the constraint, and if I change it to "250 points or less", it won't work, if I change it to "250 points or more", it won't work either.

Is there a way to:

1) Make it have no constraint, but just position at absolute x and y? (or what about the spring in the past, so that everything is more spaced out in iPhone 5?)

2) Make the NIB into a one for iPhone 4 and 4S only, so that the app works well on iPhone 4 and 4S and just "black barred" on the iPhone 5.

3) Make it work well on iPhone 5 and work well on iPhone 4 as well?

If you know solutions to only (1), (2), or (3), above, please give it regardless, as it is still a viable solution for the transition period.

It is actually very easy to reproduce: Create a simple Single View app using Xcode 4.5, and drag one button just above the center point of the screen, and another one just below the center point of the screen. Then run it on the Simulator. On iPhone 5, it is:

enter image description here

And now stop the app, and change the Device in the Simulator to iPhone 4S (3.5 inch Retina). If you don't stop the app first, the Simulator can crash. Now run the app again, and the buttons will overlap:

enter image description here

3
Showing some screenshots might help!tc.

3 Answers

6
votes

I had the same problem, and it was due to a wrong settings for autosizing. To change the autosizing, click on the control in the interface builder, go to the size inspector.

Notice the bold red I's in the autosizing grid, they control placement when the screen is resized (like when going from iPhone 3GS to iPhone 5.

Autosizing from the bottom left

I think it will work best for you if you make your autosizing look like this:

Autosizing from top left

0
votes
  1. I'm not sure, since I haven't used constraint-based layout (and won't until we drop support for iOS 5). Traditional NIB-based autoresizing will do absolute coordinates.
  2. You can't do that for just one screen, as far as I know — you can disable it for your whole app by removing [email protected].
  3. I'd go for programmatic layout, or if you want the easy way (which will be a pain to maintain), different nibs for different screen sizes. Note that you'll want to correctly handle the in-call status bar too...

EDIT: Put the two buttons in a container view and make the constraint center the container inside its parent? It won't adjust the spacing between buttons, but should look okay on both devices.

0
votes

Select your buttons and add "vertical spacing" constraint for them. And set "less than" for top/bottom margins.