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)