Skip to content

Commit

Permalink
translatesAutoresizingMaskIntoConstraints 🥲
Browse files Browse the repository at this point in the history
  • Loading branch information
PimCoumans committed Aug 19, 2022
1 parent 7882d3d commit f4612ff
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Sources/ConstraintBuilder/UIView+ConstraintBuildable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ public protocol UIViewConstraintBuildable: ContraintBuildable {

extension UIView: UIViewConstraintBuildable {
public func applyConstraints(@ConstraintBuilder _ builder: (UIView) -> [NSLayoutConstraint]) {
translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate(builder(self))
}

public func extend(to view: UIView) {
NSLayoutConstraint.build {
applyConstraints { _ in
leadingAnchor.constraint(equalTo: view.leadingAnchor)
trailingAnchor.constraint(equalTo: view.trailingAnchor)
topAnchor.constraint(equalTo: view.topAnchor)
Expand All @@ -44,14 +45,14 @@ extension UIView: UIViewConstraintBuildable {
}

public func center(in view: UIView) {
NSLayoutConstraint.build {
applyConstraints { _ in
centerXAnchor.constraint(equalTo: view.centerXAnchor)
centerYAnchor.constraint(equalTo: view.centerYAnchor)
}
}

public func extend(to layoutGuide: UILayoutGuide) {
NSLayoutConstraint.build {
applyConstraints { _ in
leadingAnchor.constraint(equalTo: layoutGuide.leadingAnchor)
trailingAnchor.constraint(equalTo: layoutGuide.trailingAnchor)
topAnchor.constraint(equalTo: layoutGuide.topAnchor)
Expand All @@ -60,7 +61,7 @@ extension UIView: UIViewConstraintBuildable {
}

public func center(in layoutGuide: UILayoutGuide) {
NSLayoutConstraint.build {
applyConstraints { _ in
centerXAnchor.constraint(equalTo: layoutGuide.centerXAnchor)
centerYAnchor.constraint(equalTo: layoutGuide.centerYAnchor)
}
Expand Down

0 comments on commit f4612ff

Please sign in to comment.