Reputation: 8704
I am having troubles with autolayout. I am trying to adjust UILabel and UIButton elements for iPhone 3.5 inches, 4 inches and 4.7 inches.
When I remove all constrains, it shows correctly on 4.7 inches, but then on 4 and 3.5 inches, elements reach the edge.
Is there a way to add something like padding on the main view, so that can be a limit for all elements inside the view?
Here is an image to explain better the problem that I am facing.
Thanks!
Upvotes: 0
Views: 135
Reputation: 1827
Go to each element and add following constraints as shown in screenshot.
The main idea here is to add trailing and leading space for each item you have on screen, so that it will maintain that much leading and trailing space for each screen screen size and will not reach edge for any screen size.
Upvotes: 2
Reputation: 4465
Use Auto-layout. In the interface builder, at the bottom right corner, there are 4 buttons. Click the third one (start counting from the left). At the top of the dialog, click the text boxes for the constraints and click "Use canvas value". Some values should appear. Add this for all four sides.
The view should now stay within edges of the screen. You might have to set some text wrapping or shrinking options to make the text become smaller to fit on screen.
Screenshots coming very soon... here as promised. Simply add the constraints and click "Add (4) constraints" at the bottom.
Upvotes: 1