iOS Simulator button not centered

后端 未结 2 985
遥遥无期
遥遥无期 2021-01-15 15:48

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 t

2条回答
  •  伪装坚强ぢ
    2021-01-15 16:29

    I was having a lot of trouble with this, too. In Xcode 6 (and Xcode 7) here is what you do.

    Use a Storyboard, not XIB files. This should be the default in Xcode 6 (and Xcode 7).

    Use Auto Layout and Size Classes. This should also be the default. If you click Main.storyboard in the Project Navigator and then show the File inspector you can make sure that these are checked:

    Select your button on the storyboard. Then click the align button on the bottom right. Select "Horizontal Center in Container" and "Vertical Center in Container". Click "Add 2 Constraints".

    If it wasn't perfectly centered already you may need to do one more thing. Click the "Resolve Auto Layout Issues" button that is two to the right of the align button. Choose "Update Frames" under "Selected Views".

    Now when you run your app it should be centered no matter what device size you are using.

    I learned all this from Creating the user interface – Auto layout. I recommend you check it out.

提交回复
热议问题