-
-
Save rubenroques/48f8bbba05bf7a01879c to your computer and use it in GitHub Desktop.
UIView extention - Fallback Constraints
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
view.addFallbackConstraints(item: labelB, attribute: .Top, relatedBy: .Equal, fallbackArrayItems:[topImageView], attribute: .Bottom, multiplier: 1, constant: 20, startPriority:110) | |
view.addFallbackConstraints(item: labelC, attribute: .Top, relatedBy: .Equal, fallbackArrayItems:[labelA,topImageView], attribute: .Bottom, multiplier: 1, constant: 20, startPriority:105) | |
view.addFallbackConstraints(item: labelD, attribute: .Top, relatedBy: .Equal, fallbackArrayItems:[labelB,labelA,topImageView], attribute: .Bottom, multiplier: 1, constant: 20, startPriority:100) | |
extension UIView { | |
func addFallbackConstraints(item view1: AnyObject, attribute attr1: NSLayoutAttribute, relatedBy relation: NSLayoutRelation, fallbackArrayItems: [AnyObject], attribute attr2: NSLayoutAttribute, multiplier: CGFloat = 1, constant c: CGFloat, startPriority: UILayoutPriority) -> UILayoutPriority { | |
var priorityDecrementer = startPriority | |
for item in fallbackArrayItems { | |
var constraint = NSLayoutConstraint(item: view1, attribute: attr1, relatedBy: relation, toItem: item, attribute: attr2, multiplier: multiplier, constant: c) | |
constraint.priority = priorityDecrementer-- | |
self.addConstraint(constraint) | |
} | |
return priorityDecrementer | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment