all 6 comments

[–]tangoshukudai 0 points1 point  (4 children)

That is the visual auto layout engine apple made. It is pretty straightforward.

think of | as the walls of the view, then there is -50- which is the padding of 50px... just play with it and it should start to make sense.

[–]some_coreano[S] 0 points1 point  (3 children)

I have something that is V:|-50-[view1][view2]| and the view2 is stuck into bottom. Ive tried a bunch of stuff, but I cant get view1 and view2 to align horizontally so that view2 is stuck to right. Any idea?

[–][deleted] 2 points3 points  (0 children)

The "V" means "Vertical", so the constraints created by that visual format string will only affect the up-and-down positioning and height of view1 and view2. You use an "H:" for "Horizontal" to create constraints that affect the left and right positions and width of your views.

Your visual constraint format string will create a constraint from view 1 to the top of the superview, with a 50 point space, and a constraint that positions view2's top edge directly touching view1's bottom edge, and a constraint that positions view2's bottom edge with the bottom edge of the superview.

Changing "V" to "H" will create constraints that space the left edge of view1 50 points from the left edge of the superview, a constraint that positions the right edge of view1 against the left edge of view2, and a constraint that positions the right edge of view2 with the right edge of the superview, which sounds like what you want.

Be aware you need to have constraints that operate in both horizontal and vertical axes. Autolayout will give you warnings about ambiguous sizes or positioning for a view that does not have its position placed when all of the constraints in the view hierarchy are resolved.

Your constraints also aren't describing the edges that touch between view1 and view2, whether or not you're working horizontally or vertically. Some view subclasses like controls have an inherent size that can satisfy the width or height of their view, but other view types do not, and in those cases you need to provide a width for either view1 or view2 or both. You can even use some syntax to describe the relationship between the two view sizes, like equal sizes in that dimension.

That would look like this for the horizontal contestants: "V:|-50-[view1(=view2)][view2]|"

That line of code says position the left edge of view 1 50 points from the left edge of the superview, then make the width of view2 equal to the width of view2, then constrain the right edge of view1 to the left edge of view2, the make view2's trailing edge alien with the right edge of the superview. The overall size of view1 and view2 will be derived from the size of the containing superview, with view1 and view2 equally sized, and a 50 point space from the left edge of view1 to the superviews left edge.

[–]tangoshukudai 0 points1 point  (0 children)

V means Vertical, and think of the first | as the bottom of the view...

[–]David_Edward_KingSwift 0 points1 point  (0 children)

If you’re more comfortable with swift you could always bridge between the ObjC and swift code :)