Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storyboard Auto Layout: "trailing space to container" vs "bottom space to bottom layout"

Could someone help me understand the difference between "trailing space to container" and "bottom space to bottom layout" in interface builder auto layout?

Interface Builder Auto Layout Constraints

I'd like to put a layout constraint in place that ties the bottom of a view to the bottom of it's superview. Both of the above sound like they should accomplish this.

Any clarification would be greatly appreciated.

like image 277
bbrame Avatar asked Oct 03 '13 19:10

bbrame


2 Answers

Leading/trailing is horizontal spacing. (It's not labeled "left" and "right" because it swaps for right-to-left languages.) Top/bottom is exactly what it says.

"To Container" and "to Layout Guide" are defined differently, but work similarly in practice. "To Container" constraints control the space between a UI element and the edge of its superview (or other containing UI element). "To Layout Guide" constraints are a special case for vertical spacing -- since views extend underneath transparent navigation/status/tab bars in iOS 7, you generally want to control where a UI element appears relative to those instead of to the edge of the view.

So...

I'd like to put a layout constraint in place that ties the bottom of a view to the bottom of it's superview.

"Bottom Space to Bottom Layout Guide" is what you want for that. That'll set spacing relative to the bottom of the superview if there's no tab bar, and relative to the tab bar if one exists.

like image 70
rickster Avatar answered Oct 31 '22 04:10

rickster


Don't forget to uncheck "Relative to margin" enter image description here

like image 6
Artem Zaytsev Avatar answered Oct 31 '22 02:10

Artem Zaytsev