This question may seem too simple to an AutoLayOut expert, but is still out of my own usual AutoLayOut usage.
I am used to play with the .Top, .Bottom, .Left, .Right, .CenterX, .CenterY attributes. But how do I do when dealing with a few objects?
For example, if I have five UILabel(s), and I want them to be vertically aligned, with a regular spacing. For the X-axis part, it is easy:
myXConstraint = NSLayoutConstraint(item: label1,
attribute: .CenterX,
relatedBy: .Equal,
toItem: superView,
attribute: .CenterX,
multiplier: 1.0,
constant: 0.0);
with a constraint like this one on each of the 5 labels, they will be vertically aligned.
But how should I write my other constraints, so that label1 appears at the top, then label2, label3 ….. label5. And I want the space at the top, the one at the bottom and the spaces between each consecutive label to be all the same value.
NSLayoutConstraint.constraintsWithVisualFormatcan be used. see, this is an example forhorizontal. you can make itvertical- iRiziya