Search code examples
iosxcode5

iOS Simulator button not centered


I'm following a tutorial to make a very simple game, yet I've run into a problem I can't figure out. When I center my button on the editor screen it all looks fine, but then running the app in the simulator seems to screw it all up:

problem

I'm running the latest version of XCode.


Solution

  • You need to use autolayout to set some constraints on the button. If you don't use autolayout, the layout just uses the raw X and Y values. So in landscape, the heights of the screen are the same, but the widths are different. Your button lays out at the same X value on both screens, so one will be centered and one won't be.

    Check out this tutorial for more info on layout constraints.