-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from PimCoumans/collections-layoutguides
Add support for collections and layout guides
- Loading branch information
Showing
3 changed files
with
61 additions
and
29 deletions.
There are no files selected for viewing
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
26 changes: 26 additions & 0 deletions
26
Sources/ConstraintBuilder/UILayoutGuide+ConstraintBuildable.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#if canImport(UIKit) | ||
import UIKit | ||
|
||
extension UILayoutGuide: ConstraintBuildable { | ||
public func applyConstraints(@ConstraintBuilder _ builder: (UILayoutGuide) -> [NSLayoutConstraint]) { | ||
NSLayoutConstraint.activate(builder(self)) | ||
} | ||
|
||
public func extend(to other: UILayoutGuide) { | ||
applyConstraints { _ in | ||
leadingAnchor.constraint(equalTo: other.leadingAnchor) | ||
trailingAnchor.constraint(equalTo: other.trailingAnchor) | ||
topAnchor.constraint(equalTo: other.topAnchor) | ||
bottomAnchor.constraint(equalTo: other.bottomAnchor) | ||
} | ||
} | ||
|
||
public func center(in other: UILayoutGuide) { | ||
applyConstraints { _ in | ||
centerXAnchor.constraint(equalTo: other.centerXAnchor) | ||
centerYAnchor.constraint(equalTo: other.centerYAnchor) | ||
} | ||
} | ||
} | ||
|
||
#endif |
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