Auto Layout: need explanation

I’m coding several dynamic views. With a little bit of struggle it seems to work. However, in the process, I try to understand why some things have to be done in a certain way. Like in the example below.

It makes sense that the first parameter refers to the control for which you’re adding the constraint. But for the “right” constraint it has to be the other way around (parent is first parameter) to make it work. Why is that. Can someone explain?

NB: One other question would be: is it possible to get code of the constraints I define via the IDE. Somehow the visual way works better for me. It would be great if I could get the code of that.

  Dim myLabel1 As New iOSLabel
  myLabel1.Text = "This is label 1:"
  
  Self.AddControl(myLabel1)
  
  Dim top As New iOSLayoutConstraint(myLabel1, _
  iOSLayoutConstraint.AttributeTypes.Top, _
  iOSLayoutConstraint.RelationTypes.Equal, _
  TopLayoutGuide, _
  iOSLayoutConstraint.AttributeTypes.Bottom, _
  1.0, _
  iOSLayoutConstraint.StandardGap)
  
  Self.AddConstraint(top)
  
  Dim left As New iOSLayoutConstraint(myLabel1, _
  iOSLayoutConstraint.AttributeTypes.Left, _
  iOSLayoutConstraint.RelationTypes.Equal, _
  Self, _
  iOSLayoutConstraint.AttributeTypes.Left, _
  1.0, _
  iOSLayoutConstraint.StandardGap)
  
  Self.AddConstraint(left)
  
  Dim right As New iOSLayoutConstraint(Self, _
  iOSLayoutConstraint.AttributeTypes.Right, _
  iOSLayoutConstraint.RelationTypes.Equal, _
  myLabel1, _
  iOSLayoutConstraint.AttributeTypes.Right, _
  1.0, _
  iOSLayoutConstraint.StandardGap)
  
  Self.AddConstraint(right)

You cannot get a list of constraints on a control, but you can get the details of a constraint that is named in the IDE. See Modifying an Existing Constraint.

I’m not sure why the right constraint would need to be set up differently. Could you create a Feedback case so we can look into it?

What I meant was for example a button in the IDE that gives you the code of the visually designed constraints so that you have a good starting point / example for coding your own dynamically created controls with layout constraints.

So it doesn’t matter what control you use for the first parameter (A - B or B - A)?

I think it should matter. Based on my understanding, the control should be first for what you are trying to do.