Skip to content

Instantly share code, notes, and snippets.

@akio0911
Created January 6, 2015 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akio0911/a8b17e7177f5c26ad504 to your computer and use it in GitHub Desktop.
Save akio0911/a8b17e7177f5c26ad504 to your computer and use it in GitHub Desktop.
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var redView = UIView()
redView.backgroundColor = UIColor.redColor()
var greenView = UIView()
greenView.backgroundColor = UIColor.greenColor()
var blueView = UIView()
blueView.backgroundColor = UIColor.blueColor()
var spacerView1 = UIView()
spacerView1.backgroundColor = UIColor(white: 7.0/8.0, alpha: 1.0)
var spacerView2 = UIView()
spacerView2.backgroundColor = UIColor(white: 7.0/8.0, alpha: 1.0)
for aView in [redView, greenView, blueView, spacerView1, spacerView2] {
view.addSubview(aView)
}
for aView in [view, redView, greenView, blueView, spacerView1, spacerView2] {
aView.setTranslatesAutoresizingMaskIntoConstraints(false)
}
let viewsDictionary = [
"redView":redView,
"greenView":greenView,
"blueView":blueView,
"spacerView1":spacerView1,
"spacerView2":spacerView2,
"topLayoutGuide":topLayoutGuide
]
let metricsDictionary = ["margin":20, "viewWidth":80]
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
"V:[topLayoutGuide]-12-[redView]",
options: NSLayoutFormatOptions(0),
metrics: nil,
views: viewsDictionary))
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
"|-margin-[redView(==viewWidth)][spacerView1][greenView(==viewWidth)][spacerView2(==spacerView1)][blueView(==viewWidth)]-margin-|",
options: .AlignAllTop,
metrics: metricsDictionary,
views: viewsDictionary))
for view in [redView, spacerView1, greenView, spacerView2, blueView] {
view.addConstraint(NSLayoutConstraint(
item: view,
attribute: .Height,
relatedBy: .Equal,
toItem: nil,
attribute: .Height,
multiplier: 0.0,
constant: 80))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment