Think of it this way: if you can do it with Autolayout in Interface Builder, you can do it using Visual Format Language as well.
However, for the use case you suggested, you'll have to describe the constraints in multiple statements:
- Set the horizontal sameness of
field
and label
- Set the vertical space of 40 px from the top of the superview to the field and the 10 px to
otherStuff
All that's required overall is that for each subview, all 4 of the necessary placement values (x, y, width and height) are defined unambiguously.
My general approach towards Autolayout by code is to write a custom library with methods that do the same things that individual constraints in Interface Builder do. Here are some sample method signatures:
+(void)addFixedHeightConstraintToView:(UIView*)view height:(CGFloat)height;
+(void)addTopMarginFromSuperviewConstraintToView:(UIView*)view topMargin:(CGFloat)topMargin;
+(void)addHorizontalSpaceConstraintFromView:(UIView*)fromView toView:(UIView*)toView horizontalSpace:(CGFloat)hSpace;
These methods are all defined with very simple and understandable VFL. Once I have these, I can easily solve the use case you described. Here's some sample code:
[CustomAutoLayout addTopMarginFromSuperviewConstraintToView:field topMargin:40];
[CustomAutoLayout addTopMarginFromSuperviewConstraintToView:label topMargin:40];
[CustomAutoLayout addHorizontalSpaceConstraintFromView:field toView:label horizontalSpace:0];
[CustomAutoLayout addVerticalSpaceConstrantFromView:field toView:otherStuff verticalSpace:10];