I have been making my first iOS app, a calculator, and I am having a hard time making it fit devices. Here is what it looks like on the iPhone 5S: http://imgur.com/mgAvo2E
When I go to the iPhone 6, it ends up looking like this: http://imgur.com/GUxM0Xw
Is there a way to get it to keep the same layout as the iPhone 5S and have everything just increase in size?
Im using Xcode 7 beta 2
You have a few options:
Use Auto Layout. This is meant to be a guide for how elements react to each other depending on screen size. This is recommended when using storyboards. It's not something I'm great with, but there are resources to help. Check the WWDC videos, or read the docs here: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html
The second is to manage the layout of all elements on your own. You will have to perform all calculations to where everything is placed, and how large they are. For example, the black bar would start at the top left corner, have a width that matches self.view's width, and a height that is 20% the height of the device. This might produce strange results there are mistakes in your calculations on where each item is placed, or run in to a screen size you don't expect.
Please see the main.storyboard in my sample project here .
Below are some screenshots on different simulators.
This is all done using constraints. The basic steps I took were:
I may have missed a step or two in my description, and I can't guarantee I added the constraints in exactly this order, but you can look at my sample project to see exactly what constraints I used.
If it seems complicated, think about how much code you would have to write to create this UI programmatically. Auto Layout makes it much easier to accomplish this, and once you get the hang of setting constraints in Xcode, it goes pretty quickly. Knowing what constraints to use is the trick. I would say it took me about 45 minutes to get the constraints right.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.