Skip to content

Instantly share code, notes, and snippets.

@davelyon
Created January 22, 2015 19:54
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 davelyon/27f5efce00bb36dbe2ad to your computer and use it in GitHub Desktop.
Save davelyon/27f5efce00bb36dbe2ad to your computer and use it in GitHub Desktop.
Swift helpers for multiple visual constraints
extension NSLayoutConstraint {
public class func visualConstraintsWithMetrics(metrics: [String : CGFloat], views: [String : UIView], options: NSLayoutFormatOptions = nil, strings: String...) -> [NSLayoutConstraint] {
return map(strings, { string in
return NSLayoutConstraint.constraintsWithVisualFormat(string, options: options, metrics: metrics, views: views) as [NSLayoutConstraint]
}).reduce([], +)
}
public class func visualConstraintsWithViews(views: [String : UIView], options: NSLayoutFormatOptions = nil, strings: String...) -> [NSLayoutConstraint] {
return map(strings, { string in
return NSLayoutConstraint.constraintsWithVisualFormat(string, options: nil, metrics: nil, views: views) as [NSLayoutConstraint]
}).reduce([], +)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment