-
-
Notifications
You must be signed in to change notification settings - Fork 6
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 #158 from 0xLeif/develop
v1.2
- Loading branch information
Showing
12 changed files
with
1,753 additions
and
41 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
49 changes: 49 additions & 0 deletions
49
Sources/SwiftUIKit/Extensions/NSLayoutConstraint+SwiftUIKit.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,49 @@ | ||
// | ||
// NSLayoutConstraint+SwiftUIKit.swift | ||
// SwiftUIKit | ||
// | ||
// Created by Zach Eriksen on 5/17/20. | ||
// | ||
|
||
import UIKit | ||
|
||
@available(iOS 10.0, *) | ||
public extension NSLayoutConstraint { | ||
|
||
/// Check if the `constraint` is connected to the `anchor` | ||
func isConnected<T>(toAnchor anchor: NSLayoutAnchor<T>) -> Bool { | ||
firstAnchor == anchor || secondAnchor == anchor | ||
} | ||
} | ||
|
||
@available(iOS 10.0, *) | ||
public extension UIView { | ||
|
||
/// The leading constraints held by the view | ||
var leadingConstraints: [NSLayoutConstraint] { | ||
constraints.filter { (constraint) -> Bool in | ||
constraint.isConnected(toAnchor: leadingAnchor) | ||
} | ||
} | ||
|
||
/// The trailing constraints held by the view | ||
var trailingConstraints: [NSLayoutConstraint] { | ||
constraints.filter { (constraint) -> Bool in | ||
constraint.isConnected(toAnchor: trailingAnchor) | ||
} | ||
} | ||
|
||
/// The top constraints held by the view | ||
var topConstraints: [NSLayoutConstraint] { | ||
constraints.filter { (constraint) -> Bool in | ||
constraint.isConnected(toAnchor: topAnchor) | ||
} | ||
} | ||
|
||
/// The bottom constraints held by the view | ||
var bottomConstraints: [NSLayoutConstraint] { | ||
constraints.filter { (constraint) -> Bool in | ||
constraint.isConnected(toAnchor: 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
Oops, something went wrong.