21

I have gone through a couple of Auto Layout tutorials such as this. However I am still not clear on what the following options do in the pin dialog

enter image description here

  1. What are the differences between standard value, manual values, and canvas values?

  2. What does the constrain to margin checkbox do?

  3. What does align do?

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
James Franco
  • 4,516
  • 10
  • 38
  • 80
  • 1
    Use Current Canvas Value means use a value which matches what you have on screen in IB. Constrain to margin, adds a margin onto view: when on a 0 offset may or may not be 0 when on screen depending on the margin. I always leave this off. – Rory McKinnel Apr 17 '15 at 17:31

1 Answers1

15

What are the differences between standard value, manual values, and canvas values?

Standard value uses "the recommended spacing for constraints that specify distance between items", which is usually around 10 points.

Current canvas value copies the value from how you have the objects currently displayed on the canvas.

Manual values are whatever you want.


What does the constrain to margin checkbox do?

This constrains to a container view's margins instead of its edges. From the docs:

“Horizontal and vertical constraints to a container view can be to the margin or to the edge. Margins correspond to the values in the layoutMargins atttribute of UIView and specify recommended minimal distances between an edge of a container view and the corresponding edge of a child.”

You can set a view's margins using the layoutMargins property.


What does align do?

This creates a constraint that edges or center of one view should be aligned with edges or center of another view. For example, in a column of text views, you might want every text field to have their leading and trailing edges aligned.

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
  • I read somewhere that we should not use magic values (hard coded values) instead we should use standard values. What does that mean and why ? – MistyD Apr 17 '15 at 18:56
  • @MistyD Using hard coded values for constraints can be problematic on different resolutions, ex retina displays, where you have more pixels so it can look very different vs. standard screens that are not retina. Using hard coded values will throw the UI off. Using standard values will avoid this issue. – harsimranb Aug 02 '16 at 18:49