Hi All,
You can add auto layout constraints by using Storyboard Interface OR by adding constraints dynamically. There are three ways to add constraint dynamically (as per Apple Inc.)
Visual Format Language is one of the way is used to add autolayout constraints dynamically.
Visual Format Language Example :-
let new_view:UIView! = UIView(frame: CGRectMake(20, 20, 100, 100));
new_view.backgroundColor = UIColor.redColor();
new_view.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(new_view);
let views = ["view": view, "newView": new_view]
let horizontalConstraints = NSLayoutConstraint.constraintsWithVisualFormat("H:|-[newView(100)]", options: NSLayoutFormatOptions.AlignAllLeft, metrics: nil, views: views)
view.addConstraints(horizontalConstraints)
let verticalConstraints = NSLayoutConstraint.constraintsWithVisualFormat("V:|-(20)-[newView(100)]", options: NSLayoutFormatOptions.AlignAllTop, metrics: nil, views: views)
view.addConstraints(verticalConstraints)
0 Comment(s)