Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS autolayout changes leading and trailing space

Tags:

ios

autolayout

I have some issues with auto layout, hopefully some of you can help me =).

I add a UIView to an empty view controller, like this: enter image description here

Then I add constraints for leading and trailing space, like this:

enter image description here

Which results in this:

enter image description here

I can't understand why it sets them as equal to -16.0. If I change those values to 0, then Xcode complains about the width of the gray UIView.

When I run the app on iPhone 5 simulator, it looks fine: enter image description here

However, when I run the app on iPhone 6 Plus simulator it adds white space on the left and on the right:

enter image description here

I don't want the gray UIView to have any space from the left of from the right no matter how big the screen is. How can I fix it? Thanks!

like image 765
almas Avatar asked Oct 19 '14 04:10

almas


People also ask

What are two properties that auto Layout constraints control on a Uiview?

Auto Layout defines margins for each view. These margins describe the preferred spacing between the edge of the view and its subviews. You can access the view's margins using either the layoutMargins or layoutMarginsGuide property. The layoutMargins property lets you get and set the margins as a UIEdgeInsets structure.

What is aspect ratio constraint IOS?

Aspect ratio constraint is used to control the width and height of a view as per a aspect ratio that you set here. There are some standard presets such as 1:1 which means width will be equal to height. Similarly other presets calculates the dimensions based on a ratio.

How do you add constraints in storyboard IOS?

Open the Align menu with the yellow button selected and check Horizontally in Container, then click Add 1 Constraint. Now, select both buttons at the same time using the Shift key and, in the Align menu, check Leading Edges. Again, actually install the constraint by clicking Add 1 Constraint.

How do constraints work in IOS?

To create constraints select the button and click the Align icon in the auto layout menu. A popover menu will appear, check both “Horizontal in container” and “Vertically in container” options to center the button on the screen. Then click the “Add 2 Constraints” button. Run the application.


1 Answers

Double click the constraint and open it. There select first or second item and deselect "Relative to margin". Then set your constant as 0.

Xcode is showing -16 because it is calculating space with respect to a margin and not the edges.

Check following link for more info on margins. Editing Auto Layout Constraints

enter image description here

like image 184
Tejesh Alimilli Avatar answered Sep 24 '22 04:09

Tejesh Alimilli