Skip to content

Instantly share code, notes, and snippets.

@onmyway133
Created April 24, 2019 13:21
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 onmyway133/46bcbb85034e47f8727e374b8bb3ad4e to your computer and use it in GitHub Desktop.
Save onmyway133/46bcbb85034e47f8727e374b8bb3ad4e to your computer and use it in GitHub Desktop.
public extension NSLayoutConstraint {
/// Disable auto resizing mask and activate constraints
///
/// - Parameter constraints: constraints to activate
static func on(_ constraints: [NSLayoutConstraint]) {
constraints.forEach {
($0.firstItem as? UIView)?.translatesAutoresizingMaskIntoConstraints = false
$0.isActive = true
}
}
static func on(_ constraintsArray: [[NSLayoutConstraint]]) {
let constraints = constraintsArray.flatMap({ $0 })
NSLayoutConstraint.on(constraints)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment