How to create the equivalent of
[View1 addConstraint:[NSLayoutConstraint constraintWithItem:View2
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:View1
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:0.0]];
in Visual Format language .
Is it even possible where View1 might not be immediate parent of View2 ?
This is what I did :
long spacing = 0 - View1.frame.size.width;
constraintString = [NSString stringWithFormat:@โH:[View1]-(%ld)-[View2]โ,spacing];
where spacing is negative in this case . But it doesnโt always work, What mistake am I doing ?
From what i see in your initial constraint you are trying to make the left edge of View2 0.0 to the left edge of View1.
Assuming the views are laid out vertically in the Visual Format Language you could do the following:
NSLayoutConstraint.constraintsWithVisualFormat(โV:[view1]-[view2]โ, options: .AlignAllLeft, metrics: nil, views: [โview1โ: view1, โview2โ: view2])
This will in a vertical layout make the view1 left and view2 left the exact same provided you had some horizontal guide on at least on of those two views.
If this is not what you were referring too please let me know so i can try and assist further.
I am getting uncaught exception even after activating the constraints . Kindly help me. - Christina
This needs to be updated for compatibility with Xcode 9
This tutorial is more than six months old so questions regarding it are no longer supported for the moment. We will update it as soon as possible. Thank you! :]