class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var aView = UIView()
aView.backgroundColor = UIColor.redColor()
aView.setTranslatesAutoresizingMaskIntoConstraints(false)
self.view .addSubview(aView)
//添加约束
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-[aView]-|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["aView":aView]))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-20-[aView(==50)]|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["aView":aView]))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}