Skip to content

Instantly share code, notes, and snippets.

@TomoyaOnishi
Created January 11, 2015 06:45
Show Gist options
  • Save TomoyaOnishi/4056eab4fe3e4ef97e66 to your computer and use it in GitHub Desktop.
Save TomoyaOnishi/4056eab4fe3e4ef97e66 to your computer and use it in GitHub Desktop.
override func viewDidLoad() {
super.viewDidLoad()
let view = UIView(frame: CGRectZero)
view.setTranslatesAutoresizingMaskIntoConstraints(false)
view.backgroundColor = UIColor.redColor()
self.view.addSubview(view)
let views = ["view": view]
let h = NSLayoutConstraint.constraintsWithVisualFormat("|[view]|", options: nil, metrics: nil, views: views)
let v = NSLayoutConstraint.constraintsWithVisualFormat("V:|[view]|", options: nil, metrics: nil, views: views)
// This method will be deprecated in a future release.
// self.view.addConstraints(h)
// self.view.addConstraints(v)
NSLayoutConstraint.activateConstraints(h)
NSLayoutConstraint.activateConstraints(v)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment