/centerX_align_using_constraint Secret
Created
June 25, 2016 13:17
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
// Creating constraints using NSLayoutConstraint: from iOS 6.0 | |
NSLayoutConstraint(item: firstView, attribute: .Top, relatedBy: .Equal, toItem: secondView, attribute: .Bottom, multiplier: 1.0, constant: padding).active = true | |
NSLayoutConstraint(item: firstView, attribute: .CenterX, relatedBy: .Equal, toItem: secondView, attribute: .CenterX, multiplier: 1.0, constant: 0).active = true | |
NSLayoutConstraint(item: firstView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: equalHeight).active = true |
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
// Creating constraints using Visual Format Language: from iOS 6.0 | |
let views : [String : AnyObject] = ["centerXLabel": centerXLabel, "topEdgesLabel": topEdgesLabel] | |
var allConstraints = [NSLayoutConstraint]() | |
let constraint1 = NSLayoutConstraint.constraintsWithVisualFormat("V:[topEdgesLabel]-(<=130)-[centerXLabel(\(50))]",options: NSLayoutFormatOptions.AlignAllCenterX, metrics: nil, views: views) | |
allConstraints += constraint1 | |
NSLayoutConstraint.activateConstraints(allConstraints) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment