Last active
March 13, 2017 22:52
-
-
Save daltonclaybrook/983dc39f9af0d611adc709eb32e13f8e to your computer and use it in GitHub Desktop.
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
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