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
[logoImageView, welcomeLabel, dismissButton].forEach { | |
self.addSubview($0) | |
$0.translatesAutoresizingMaskIntoConstraints = false | |
} |
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
addSubviewsUsingAutoLayout(logoImageView, welcomeLabel, dismissButton) |
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
extension NSLayoutAnchor { | |
func test() {} | |
} |
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
@objc extension NSLayoutAnchor { | |
func test() {} | |
} |
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
@objc extension NSLayoutAnchor { | |
@discardableResult | |
func constrain(equalTo anchor: NSLayoutAnchor, | |
with constant: CGFloat = 0.0, | |
isActive: Bool = true) -> NSLayoutConstraint { | |
let constraint = self.constraint(equalTo: anchor, constant: constant) | |
constraint.isActive = isActive | |
return constraint |
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
@objc extension NSLayoutAnchor { | |
@discardableResult | |
func constrain(_ relation: NSLayoutConstraint.Relation = .equal, | |
to anchor: NSLayoutAnchor, | |
with constant: CGFloat = 0.0, | |
isActive: Bool = true) -> NSLayoutConstraint { | |
let constraint: NSLayoutConstraint |
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
let a = UIView() | |
let b = UIView() | |
a.addSubviewsUsingAutoLayout(b) | |
// Constraint set as equal to a.topAnchor | |
b.topAnchor.constrain(a.topAnchor) | |
// Constraint set as greater than or equal to a.bottomAnchor | |
b.bottomAnchor.constrain(.greaterThanOrEqual, to: a.bottomAnchor) |
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
extension NSLayoutDimension { | |
@discardableResult | |
func constrain(_ relation: NSLayoutConstraint.Relation = .equal, | |
to anchor: NSLayoutDimension, | |
with constant: CGFloat = 0.0, | |
multiplyBy multiplier: CGFloat = 1.0, | |
isActive: Bool = true) -> NSLayoutConstraint { | |
let constraint: NSLayoutConstraint |
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
let bWidth = b.widthAnchor.constraint(equalToConstant: 50.0) | |
bWidth.priority = .defaultHigh | |
// or if you want between .defaultHigh and .required 👇 🤮 | |
bWidth.priority = UILayoutPriority(UILayoutPriority.defaultHigh.rawValue + 1) |
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
@objc extension NSLayoutAnchor { | |
@discardableResult | |
func constrain(_ relation: NSLayoutConstraint.Relation = .equal, | |
to anchor: NSLayoutAnchor, | |
with constant: CGFloat = 0.0, | |
prioritizeAs priority: UILayoutPriority = .required, | |
isActive: Bool = true) -> NSLayoutConstraint { | |
let constraint: NSLayoutConstraint |