Created
January 6, 2015 06:31
-
-
Save akio0911/a8b17e7177f5c26ad504 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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