Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode auto layout constraints - why defaulting to negative padding?

I am simply adding a UIView into the main view of a view controller. I want the height to always be 64px, but the width to stretch to the width of the screen.

However, when I go to add constraints, the left and right padding default to -16, even though the view is stretched all the way across its parent view. Even if I set these back to 0, when I run the app the -16 padding is added back in. What is going on here?

enter image description here

enter image description here

enter image description here

like image 301
soleil Avatar asked Sep 12 '14 19:09

soleil


People also ask

What does constrain to margins mean in Xcode?

The “Constrain to margins” checkbox determines whether constraints to the superview use the superview's margins or its edges. The lower portion of the popover lets you set the item's width or height. The Width and Height constraints default to the current canvas size, though you can type in different values.

What is auto layout constraints in Swift?

Auto Layout constraints allow us to create views that dynamically adjust to different size classes and positions. The constraints will make sure that your views adjust to any size changes without having to manually update frames or positions.


1 Answers

Uncheck "Constrain to margins" checkbox in the pin menu (the first image in the question) while adding spacing to nearest neighbor for the new constraints.

like image 139
Ganesh Kamath Avatar answered Jan 28 '23 17:01

Ganesh Kamath