malhobayyeb
malhobayyeb

Reputation: 2873

How to use Auto Layout to stick a view from the right to the left of the screen?

In Xcode with Swift and Auto Layout.

I placed a MapView to and applied Auto Layout constraints :

Trailing Space to superview: Equals 0

Leading Space to superview: Equals 0

but these leave a space of 16px on each side. So I changed them to:

Trailing Space to superview: Equals -16

Leading Space to superview: Equals -16

That worked just fine for iPhone 6, but when I tested it with iPhone 6 Plus I found a space of 4px on each side. If I changed my constraints to -20s then for the iPhone 6 the two 4px will be hidden.

Is there a way to stick a view to the edge for both devices using Auto Layout without specifying pixels?

Upvotes: 1

Views: 754

Answers (2)

djromero
djromero

Reputation: 19641

Uncheck Constrain to margins in the "Pin" dialog, and use 0 as left/right space:

enter image description here

Upvotes: 4

FelixMLians
FelixMLians

Reputation: 95

You can use size classes,then add new constraints,problem solved!!

Upvotes: 0

Related Questions