Skip to content

Instantly share code, notes, and snippets.

@kazukitanaka0611
Created February 5, 2015 07:43
Show Gist options
  • Save kazukitanaka0611/097398cfa6d253267668 to your computer and use it in GitHub Desktop.
Save kazukitanaka0611/097398cfa6d253267668 to your computer and use it in GitHub Desktop.
AutoLayout Code
let myView = UIView()
myView.setTranslatesAutoresizingMaskIntoConstraints(false)
myView.backgroundColor = UIColor.greenColor()
self.view.addSubview(myView)
self.view.addConstraints([
NSLayoutConstraint(item: myView,
attribute: .Width,
relatedBy: .Equal,
toItem: self.view,
attribute: .Width,
multiplier: 4.0/5.0,
constant: 0.0),
NSLayoutConstraint(item: myView,
attribute: .Height,
relatedBy: .Equal,
toItem: self.view,
attribute: .Height,
multiplier: 2.0/3.0,
constant: 0.0),
NSLayoutConstraint(item: myView,
attribute: .CenterX,
relatedBy: .Equal,
toItem: self.view,
attribute: .CenterX,
multiplier: 1.0,
constant: 0.0),
NSLayoutConstraint(item: myView,
attribute: .Top,
relatedBy: .Equal,
toItem: self.view,
attribute: .Top,
multiplier: 1.0,
constant: 30.0),
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment