Skip to content

Instantly share code, notes, and snippets.

@daltonclaybrook
Last active March 13, 2017 22:52
Show Gist options
  • Save daltonclaybrook/983dc39f9af0d611adc709eb32e13f8e to your computer and use it in GitHub Desktop.
Save daltonclaybrook/983dc39f9af0d611adc709eb32e13f8e to your computer and use it in GitHub Desktop.
import UIKit
extension UIView { // Constraints
func constrainEdgesToSuperview() {
constrainEdgesToSuperview(with: .zero)
}
func constrainEdgesToSuperview(with inset: UIEdgeInsets) {
guard let superview=superview else { assertionFailure("must have a superview"); return }
translatesAutoresizingMaskIntoConstraints = false
superview.leftAnchor.constraint(equalTo: leftAnchor, constant: inset.left).isActive = true
superview.topAnchor.constraint(equalTo: topAnchor, constant: inset.top).isActive = true
superview.rightAnchor.constraint(equalTo: rightAnchor, constant: -inset.right).isActive = true
superview.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -inset.bottom).isActive = true
}
}
extension UIView { // Actions
class func performWithoutActions(block: () -> ()) {
CATransaction.begin()
CATransaction.setDisableActions(true)
block()
CATransaction.commit()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment