Reputation: 517
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:label1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:label2 attribute:NSLayoutAttributeTop multiplier:1.0 constant:5];
I tried to write this code in VFL,but it seems the VFL only provide the NSLayoutFormatAlignAllTop property. So I can't set label1 is lower than label2 in 5 points.
I want to know if this constraint can't be written in VFL.
Upvotes: 0
Views: 347
Reputation: 27438
You can do something like,
NSArray *verticalConstraints1 =[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[label1]-20-|" options:0 metrics:nil views:views]; // this set top and bottom vertical constraint
NSArray *verticalConstraints1 =[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[label1]" options:0 metrics:nil views:views]; // this will set only top
NSArray *horizontalConstraints =[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[label1]-20-[label2]-20-|" options:0 metrics:nil views:views]; //this will vertical constraint between two label and top and bottom to label1 and label2 respactively
You can refer this link for more details.
Update :
For example,
|-[button1(button2)]-[button2]-|
This constraints means, button1 must be the same width as button2, they have a standard spacing between them, button1 is a standard spacing from the left edge of the superview, and button2 is a standard spacing from the right edge of the superview.
If here you take button1(button2/2)
then it's mean it's half width of button2. If you need this scenario in height manner then just add V:
before statement.
another examle,
V:|-(==padding)-[imageView]->=0-[button]-(==padding)-|
This constraints mean,
The top of the image view must be padding points from the top of the superview
The bottom of the image view must be greater than or equal to 0 points from the top of the button
The bottom of the button must be padding points from the bottom of the superview.
|[button(==200@750)]-[label]|
This constrains means, The button’s width should be 200 points, with a priority of 750.
|-30.0@200-[label]
The label should be spaced 30 points from the left of the superview, with a priority of 200.
In short you can set any type of constraints in VFL
format.
Refer this link as reference for more details!
Hope this will help :)
Upvotes: 2