iOS 8 Autolayout - Visual Format Language how to add constraint to superview's edge

1.2k Views Asked by At

Can I pin my view to my superView's edge instead of its layout margin through VFL? Can I be even flexible to toggle "Relative to margin" on myView as well?

NO VFL (this is what I want to achieve with Visual Format Language):

  var constraintLeft = NSLayoutConstraint(item: myView, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: self.view!, attribute: NSLayoutAttribute.Left, multiplier: 1.0, constant: 0)

  var constraintRight = NSLayoutConstraint(item: myView!, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: self.view!, attribute: NSLayoutAttribute.Right, multiplier: 1.0, constant: 0)

VFL :

 var constraintHorizontal = NSLayoutConstraint.constraintsWithVisualFormat("H:|-[myView]-|", options: NSLayoutFormatOptions(0),metrics: nil, views: viewsDictionary)
1

There are 1 best solutions below

2
On BEST ANSWER

You can use "H:|[myView]|" instead of "H:|-[myView]-|" to constrain to the edge.