refactored to use protocol

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-22 16:05:36 -05:00
parent f39ba505b2
commit 071e627fe6
6 changed files with 56 additions and 485 deletions

View File

@ -48,7 +48,7 @@
EA33623E2892EE950071C351 /* UIDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33623D2892EE950071C351 /* UIDevice.swift */; }; EA33623E2892EE950071C351 /* UIDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33623D2892EE950071C351 /* UIDevice.swift */; };
EA3362402892EF6C0071C351 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33623F2892EF6B0071C351 /* Label.swift */; }; EA3362402892EF6C0071C351 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33623F2892EF6B0071C351 /* Label.swift */; };
EA33624728931B050071C351 /* Initable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33624628931B050071C351 /* Initable.swift */; }; EA33624728931B050071C351 /* Initable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33624628931B050071C351 /* Initable.swift */; };
EA471F382A9545A700CE9E58 /* UILayoutGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA471F372A9545A700CE9E58 /* UILayoutGuide.swift */; }; EA471F3A2A95587500CE9E58 /* LayoutConstraintable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA471F392A95587500CE9E58 /* LayoutConstraintable.swift */; };
EA4DB18528CA967F00103EE3 /* SelectorGroupHandlerBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4DB18428CA967F00103EE3 /* SelectorGroupHandlerBase.swift */; }; EA4DB18528CA967F00103EE3 /* SelectorGroupHandlerBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4DB18428CA967F00103EE3 /* SelectorGroupHandlerBase.swift */; };
EA4DB2FD28D3D0CA00103EE3 /* AnyEquatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4DB2FC28D3D0CA00103EE3 /* AnyEquatable.swift */; }; EA4DB2FD28D3D0CA00103EE3 /* AnyEquatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4DB2FC28D3D0CA00103EE3 /* AnyEquatable.swift */; };
EA4DB30228DCBCA500103EE3 /* Badge.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4DB30128DCBCA500103EE3 /* Badge.swift */; }; EA4DB30228DCBCA500103EE3 /* Badge.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4DB30128DCBCA500103EE3 /* Badge.swift */; };
@ -195,7 +195,7 @@
EA33623D2892EE950071C351 /* UIDevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIDevice.swift; sourceTree = "<group>"; }; EA33623D2892EE950071C351 /* UIDevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIDevice.swift; sourceTree = "<group>"; };
EA33623F2892EF6B0071C351 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = "<group>"; }; EA33623F2892EF6B0071C351 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = "<group>"; };
EA33624628931B050071C351 /* Initable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Initable.swift; sourceTree = "<group>"; }; EA33624628931B050071C351 /* Initable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Initable.swift; sourceTree = "<group>"; };
EA471F372A9545A700CE9E58 /* UILayoutGuide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UILayoutGuide.swift; sourceTree = "<group>"; }; EA471F392A95587500CE9E58 /* LayoutConstraintable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutConstraintable.swift; sourceTree = "<group>"; };
EA4DB18428CA967F00103EE3 /* SelectorGroupHandlerBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectorGroupHandlerBase.swift; sourceTree = "<group>"; }; EA4DB18428CA967F00103EE3 /* SelectorGroupHandlerBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectorGroupHandlerBase.swift; sourceTree = "<group>"; };
EA4DB2FC28D3D0CA00103EE3 /* AnyEquatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyEquatable.swift; sourceTree = "<group>"; }; EA4DB2FC28D3D0CA00103EE3 /* AnyEquatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyEquatable.swift; sourceTree = "<group>"; };
EA4DB30128DCBCA500103EE3 /* Badge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Badge.swift; sourceTree = "<group>"; }; EA4DB30128DCBCA500103EE3 /* Badge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Badge.swift; sourceTree = "<group>"; };
@ -469,7 +469,6 @@
EA3361A7288B23300071C351 /* UIColor.swift */, EA3361A7288B23300071C351 /* UIColor.swift */,
EA81410F2A127066004F60D2 /* UIColor+VDSColor.swift */, EA81410F2A127066004F60D2 /* UIColor+VDSColor.swift */,
EA33623D2892EE950071C351 /* UIDevice.swift */, EA33623D2892EE950071C351 /* UIDevice.swift */,
EA471F372A9545A700CE9E58 /* UILayoutGuide.swift */,
EAF7F0B6289C12A600B287F5 /* UITapGestureRecognizer.swift */, EAF7F0B6289C12A600B287F5 /* UITapGestureRecognizer.swift */,
EA8E40902A7D3F6300934ED3 /* UIView+Accessibility.swift */, EA8E40902A7D3F6300934ED3 /* UIView+Accessibility.swift */,
EAB5FED329267EB300998C17 /* UIView+NSLayoutConstraint.swift */, EAB5FED329267EB300998C17 /* UIView+NSLayoutConstraint.swift */,
@ -494,6 +493,7 @@
EAF7F0A1289AFB3900B287F5 /* Errorable.swift */, EAF7F0A1289AFB3900B287F5 /* Errorable.swift */,
EA3361AE288B26310071C351 /* FormFieldable.swift */, EA3361AE288B26310071C351 /* FormFieldable.swift */,
EA33624628931B050071C351 /* Initable.swift */, EA33624628931B050071C351 /* Initable.swift */,
EA471F392A95587500CE9E58 /* LayoutConstraintable.swift */,
EA985C7C297DAED300F2FF2E /* Primitive.swift */, EA985C7C297DAED300F2FF2E /* Primitive.swift */,
EAF7F0A5289B0CE000B287F5 /* Resetable.swift */, EAF7F0A5289B0CE000B287F5 /* Resetable.swift */,
EA3361C8289054C50071C351 /* Surfaceable.swift */, EA3361C8289054C50071C351 /* Surfaceable.swift */,
@ -954,7 +954,6 @@
EA5F86D02A1F936100BC83E4 /* TabsContainer.swift in Sources */, EA5F86D02A1F936100BC83E4 /* TabsContainer.swift in Sources */,
EAF7F0B1289B177F00B287F5 /* ColorLabelAttribute.swift in Sources */, EAF7F0B1289B177F00B287F5 /* ColorLabelAttribute.swift in Sources */,
EAC9258F2911C9DE00091998 /* EntryField.swift in Sources */, EAC9258F2911C9DE00091998 /* EntryField.swift in Sources */,
EA471F382A9545A700CE9E58 /* UILayoutGuide.swift in Sources */,
EAB1D2EA28AE84AA00DAE764 /* UIControlPublisher.swift in Sources */, EAB1D2EA28AE84AA00DAE764 /* UIControlPublisher.swift in Sources */,
EAD068922A560B65002E3A2D /* LoaderViewController.swift in Sources */, EAD068922A560B65002E3A2D /* LoaderViewController.swift in Sources */,
EABFEB642A26473700C4C106 /* NSAttributedString.swift in Sources */, EABFEB642A26473700C4C106 /* NSAttributedString.swift in Sources */,
@ -967,6 +966,7 @@
EA0D1C372A681CCE00E5C127 /* ToggleView.swift in Sources */, EA0D1C372A681CCE00E5C127 /* ToggleView.swift in Sources */,
EAF7F0B9289C139800B287F5 /* ColorConfiguration.swift in Sources */, EAF7F0B9289C139800B287F5 /* ColorConfiguration.swift in Sources */,
EA3361BD288B2C760071C351 /* TypeAlias.swift in Sources */, EA3361BD288B2C760071C351 /* TypeAlias.swift in Sources */,
EA471F3A2A95587500CE9E58 /* LayoutConstraintable.swift in Sources */,
EAB1D2CF28ABEF2B00DAE764 /* Typography.swift in Sources */, EAB1D2CF28ABEF2B00DAE764 /* Typography.swift in Sources */,
EA0D1C3B2A6AD51B00E5C127 /* Typogprahy+Styles.swift in Sources */, EA0D1C3B2A6AD51B00E5C127 /* Typogprahy+Styles.swift in Sources */,
EAF7F09A2899B17200B287F5 /* CATransaction.swift in Sources */, EAF7F09A2899B17200B287F5 /* CATransaction.swift in Sources */,

View File

@ -239,7 +239,7 @@ open class ButtonIcon: Control {
layoutGuideHeightConstraint = iconLayoutGuide.height(constant: size.containerSize) layoutGuideHeightConstraint = iconLayoutGuide.height(constant: size.containerSize)
//pin layout guide //pin layout guide
iconLayoutGuide.pinToOwningView() iconLayoutGuide.pinToSuperView()
//determines the center point of the icon //determines the center point of the icon
centerXConstraint = icon.centerXAnchor.constraint(equalTo: iconLayoutGuide.centerXAnchor, constant: 0) centerXConstraint = icon.centerXAnchor.constraint(equalTo: iconLayoutGuide.centerXAnchor, constant: 0)

View File

@ -132,7 +132,7 @@ extension Tabs {
isAccessibilityElement = true isAccessibilityElement = true
//pin layoutguide //pin layoutguide
layoutGuide.pinToOwningView() layoutGuide.pinToSuperView()
//pin trailing //pin trailing
label.pinTrailing(layoutGuide.trailingAnchor) label.pinTrailing(layoutGuide.trailingAnchor)

View File

@ -132,7 +132,7 @@ open class TabsContainer: View {
stackView.addArrangedSubview(tabMenu) stackView.addArrangedSubview(tabMenu)
stackView.addArrangedSubview(contentView) stackView.addArrangedSubview(contentView)
tabMenuLayoutGuide.pinToOwningView() tabMenuLayoutGuide.pinToSuperView()
} }
/// Function used to make changes to the View based off a change events or from local properties. /// Function used to make changes to the View based off a change events or from local properties.

View File

@ -10,466 +10,11 @@ import UIKit
import VDSFormControlsTokens import VDSFormControlsTokens
extension UIView { extension UIView {
public func constraint(with identifier: String) -> NSLayoutConstraint? { public func constraint(with identifier: String) -> NSLayoutConstraint? {
return constraints.first { $0.identifier == identifier } return constraints.first { $0.identifier == identifier }
} }
} }
//--------------------------------------------------
// MARK: - Pinning
//--------------------------------------------------
extension UIView {
@discardableResult
/// Pins each to the all 4 anchor points to a view.
/// - Parameters:
/// - view: View that you will be pinned within.
/// - edges: Insets for each side.
/// - Returns: Yourself.
public func pin(_ view: UIView, with edges: UIEdgeInsets = UIEdgeInsets.zero) -> Self {
pinLeading(view.leadingAnchor, edges.left)
pinTrailing(view.trailingAnchor, edges.right)
pinTop(view.topAnchor, edges.top)
pinBottom(view.bottomAnchor, edges.bottom)
return self
}
@discardableResult
/// Pins each to the all 4 anchor points to the view you are set within.
/// - Parameter edges: Insets for each side.
/// - Returns: Yourself.
public func pinToSuperView(_ edges: UIEdgeInsets = UIEdgeInsets.zero) -> Self {
if let superview {
pin(superview, with: edges)
}
return self
}
}
//--------------------------------------------------
// MARK: - HeightAnchor
//--------------------------------------------------
extension UIView {
@discardableResult
/// Adds a heightAnchor.
/// - Parameter constant: Constant size.
/// - Returns: Yourself.
public func height(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self {
height(constant: constant, priority: priority)
return self
}
@discardableResult
/// Adds a heightAnchor where the height constant passed in using a greaterThanOrEqualTo Constraint.
/// - Parameter constant: Constant size.
/// - Returns: Yourself.
public func heightGreaterThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self {
heightGreaterThanEqualTo(constant: constant, priority: priority)
return self
}
@discardableResult
/// Adds a heightAnchor where the height constant passed in using a lessThanOrEqualTo Constraint.
/// - Parameter constant: Constant size.
/// - Returns: Yourself.
public func heightLessThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self {
heightLessThanEqualTo(constant: constant, priority: priority)
return self
}
@discardableResult
/// Adds a heightAnchor for the constant passed into the method.
/// - Parameter constant: Constant size.
/// - Returns: The Constraint that was created.
public func height(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint {
heightAnchor.constraint(equalToConstant: constant).with { $0.priority = priority; $0.isActive = true }
}
@discardableResult
/// Adds a heightAnchor where the constant passed in using a greaterThanOrEqualTo Constraint.
/// - Parameter constant: Constant size.
/// - Returns: The Constraint that was created.
public func heightGreaterThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint {
heightAnchor.constraint(greaterThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true }
}
@discardableResult
/// Adds a heightAnchor where the constant passed in using a lessThanOrEqualTo Constraint.
/// - Parameter constant: Constant size.
/// - Returns: The Constraint that was created.
public func heightLessThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint {
heightAnchor.constraint(lessThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true }
}
}
//--------------------------------------------------
// MARK: - WidthAnchor
//--------------------------------------------------
extension UIView {
@discardableResult
/// Adds a widthAnchor.
/// - Parameter constant: Width Constant size.
/// - Returns: Yourself.
public func width(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self {
width(constant: constant, priority: priority)
return self
}
@discardableResult
/// Adds a widthAnchor where the constant passed in using a greaterThanOrEqualTo Constraint.
/// - Parameter constant: Constant size.
/// - Returns: Yourself.
public func widthGreaterThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self {
widthGreaterThanEqualTo(constant: constant, priority: priority)
return self
}
@discardableResult
/// Adds a widthAnchor where the constant passed in using a lessThanOrEqualTo Constraint.
/// - Parameter constant: Constant size.
/// - Returns: Yourself.
public func widthLessThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self {
widthLessThanEqualTo(constant: constant, priority: priority)
return self
}
@discardableResult
/// Adds a widthAnchor for the constant passed into the method.
/// - Parameter constant: Constant size.
/// - Returns: The Constraint that was created.
public func width(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint {
widthAnchor.constraint(equalToConstant: constant).with { $0.priority = priority; $0.isActive = true }
}
@discardableResult
/// Adds a widthAnchor with the constant passed in using a greaterThanOrEqualTo Constraint.
/// - Parameter constant: Constant size.
/// - Returns: The Constraint that was created.
public func widthGreaterThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint {
widthAnchor.constraint(greaterThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true }
}
@discardableResult
/// Adds a widthAnchor with the constant passed in using a lessThanOrEqualTo Constraint.
/// - Parameter constant: Constant size.
/// - Returns: The Constraint that was created.
public func widthLessThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint {
widthAnchor.constraint(lessThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true }
}
}
//--------------------------------------------------
// MARK: - TopAnchor
//--------------------------------------------------
extension UIView {
@discardableResult
/// Adds a topAnchor.
/// - Parameter constant: Constant size.
/// - Returns: Yourself.
public func pinTop(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
return pinTop(nil, constant, priority)
}
@discardableResult
/// Adds a topAnchor to a specific YAxisAnchor.
/// - Parameter anchor:The anchor in which to attach the topAnchor
/// - constant: Constant size.
/// - Returns: Yourself.
public func pinTop(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
pinTop(anchor: anchor, constant: constant, priority: priority)
return self
}
@discardableResult
/// Adds a topAnchor to a specific YAxisAnchor passed in using a lessThanOrEqualTo Constraint
/// - Parameter anchor:The anchor in which to attach the topAnchor
/// - constant: Constant size.
/// - Returns: Yourself.
public func pinTopLessThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
pinTopLessThanOrEqualTo(anchor: anchor, constant: constant, priority: priority)
return self
}
@discardableResult
/// Adds a topAnchor to a specific YAxisAnchor passed in using a greaterThanOrEqualTo Constraint
/// - Parameter anchor:The anchor in which to attach the topAnchor
/// - constant: Constant size.
/// - Returns: Yourself.
public func pinTopGreaterThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
pinTopGreaterThanOrEqualTo(anchor: anchor, constant: constant, priority: priority)
return self
}
@discardableResult
/// Adds a topAnchor for the constant passed into the method.
/// - Parameter anchor:The anchor in which to attach the topAnchor
/// - constant: Constant size.
/// - Returns: The Constraint that was created.
public func pinTop(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutYAxisAnchor? = anchor ?? superview?.topAnchor
guard let found else { return nil }
return topAnchor.constraint(equalTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true }
}
@discardableResult
/// Adds a topAnchor with the constant passed in using a lessThanOrEqualTo Constraint.
/// - Parameter anchor:The anchor in which to attach the topAnchor
/// - constant: Constant size.
/// - Returns: The Constraint that was created.
public func pinTopLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutYAxisAnchor? = anchor ?? superview?.topAnchor
guard let found else { return nil }
return topAnchor.constraint(lessThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true }
}
@discardableResult
/// Adds a topAnchor with the constant passed in using a greaterThanOrEqualTo Constraint.
/// - Parameter anchor:The anchor in which to attach the topAnchor
/// - constant: Constant size.
/// - Returns: The Constraint that was created.
public func pinTopGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutYAxisAnchor? = anchor ?? superview?.topAnchor
guard let found else { return nil }
return topAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true }
}
}
//--------------------------------------------------
// MARK: - BottomAnchor
//--------------------------------------------------
extension UIView {
@discardableResult
/// Adds a bottomAnchor.
/// - Parameter constant: Constant size.
/// - Returns: Yourself.
public func pinBottom(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
return pinBottom(nil, constant, priority)
}
@discardableResult
/// Adds a bottomAnchor to a specific YAxisAnchor.
/// - Parameter anchor:The anchor in which to attach the bottomAnchor
/// - constant: Constant size.
/// - Returns: Yourself.
public func pinBottom(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
pinBottom(anchor: anchor, constant: constant, priority: priority)
return self
}
@discardableResult
/// Adds a bottomAnchor to a specific YAxisAnchor passed in using a lessThanOrEqualTo Constraint
/// - Parameter anchor:The anchor in which to attach the bottomAnchor
/// - constant: Constant size.
/// - Returns: Yourself.
public func pinBottomLessThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
pinBottomLessThanOrEqualTo(anchor: anchor, constant: constant, priority: priority)
return self
}
@discardableResult
/// Adds a bottomAnchor to a specific YAxisAnchor passed in using a greaterThanOrEqualTo Constraint
/// - Parameter anchor:The anchor in which to attach the bottomAnchor
/// - constant: Constant size.
/// - Returns: Yourself.
public func pinBottomGreaterThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
pinBottomGreaterThanOrEqualTo(anchor: anchor, constant: constant, priority: priority)
return self
}
@discardableResult
/// Adds a bottomAnchor for the constant passed into the method.
/// - Parameter anchor:The anchor in which to attach the bottomAnchor
/// - constant: Constant size.
/// - Returns: The Constraint that was created.
public func pinBottom(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutYAxisAnchor? = anchor ?? superview?.bottomAnchor
guard let found else { return nil }
return bottomAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
}
@discardableResult
/// Adds a bottomAnchor with the constant passed in using a lessThanOrEqualTo Constraint.
/// - Parameter anchor:The anchor in which to attach the bottomAnchor
/// - constant: Constant size.
/// - Returns: The Constraint that was created.
public func pinBottomLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutYAxisAnchor? = anchor ?? superview?.bottomAnchor
guard let found else { return nil }
return bottomAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
}
@discardableResult
/// Adds a bottomAnchor with the constant passed in using a greaterThanOrEqualTo Constraint.
/// - Parameter anchor:The anchor in which to attach the bottomAnchor
/// - constant: Constant size.
/// - Returns: The Constraint that was created.
public func pinBottomGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutYAxisAnchor? = anchor ?? superview?.bottomAnchor
guard let found else { return nil }
return bottomAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
}
}
//--------------------------------------------------
// MARK: - LeadingAnchor
//--------------------------------------------------
extension UIView {
@discardableResult
/// Adds a leadingAnchor.
/// - Parameter constant: Constant size.
/// - Returns: Yourself.
public func pinLeading(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
return pinLeading(nil, constant, priority)
}
@discardableResult
/// Adds a leadingAnchor to a specific XAxisAnchor.
/// - Parameter anchor:The anchor in which to attach the leadingAnchor.
/// - constant: Constant size.
/// - Returns: Yourself.
public func pinLeading(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
pinLeading(anchor: anchor, constant: constant, priority: priority)
return self
}
@discardableResult
/// Adds a leadingAnchor to a specific XAxisAnchor passed in using a greaterThanOrEqualTo Constraint
/// - Parameter anchor:The anchor in which to attach the leadingAnchor
/// - constant: Constant size.
/// - Returns: Yourself.
public func pinLeadingLessThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
pinLeadingLessThanOrEqualTo(anchor: anchor, constant: constant, priority: priority)
return self
}
@discardableResult
/// Adds a leadingAnchor to a specific XAxisAnchor passed in using a greaterThanOrEqualTo Constraint
/// - Parameter anchor:The anchor in which to attach the leadingAnchor
/// - constant: Constant size.
/// - Returns: Yourself.
public func pinLeadingGreaterThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
pinLeadingGreaterThanOrEqualTo(anchor: anchor, constant: constant, priority: priority)
return self
}
@discardableResult
/// Adds a leadingAnchor for the constant passed into the method.
/// - Parameter anchor:The anchor in which to attach the leadingAnchor
/// - constant: Constant size.
/// - Returns: The Constraint that was created.
public func pinLeading(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutXAxisAnchor? = anchor ?? superview?.leadingAnchor
guard let found else { return nil }
return leadingAnchor.constraint(equalTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true }
}
@discardableResult
/// Adds a leadingAnchor with the constant passed in using a lessThanOrEqualTo Constraint.
/// - Parameter anchor:The anchor in which to attach the leadingAnchor
/// - constant: Constant size.
/// - Returns: The Constraint that was created.
public func pinLeadingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutXAxisAnchor? = anchor ?? superview?.leadingAnchor
guard let found else { return nil }
return leadingAnchor.constraint(lessThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true }
}
@discardableResult
/// Adds a leadingAnchor with the constant passed in using a greaterThanOrEqualTo Constraint.
/// - Parameter anchor:The anchor in which to attach the leadingAnchor
/// - constant: Constant size.
/// - Returns: The Constraint that was created.
public func pinLeadingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutXAxisAnchor? = anchor ?? superview?.leadingAnchor
guard let found else { return nil }
return leadingAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true }
}
}
//--------------------------------------------------
// MARK: - TrailingAnchor
//--------------------------------------------------
extension UIView {
@discardableResult
/// Adds a trailingAnchor.
/// - Parameter constant: Constant size.
/// - Returns: Yourself.
public func pinTrailing(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
pinTrailing(nil, constant)
}
@discardableResult
/// Adds a trailingAnchor to a specific XAxisAnchor.
/// - Parameter anchor:The anchor in which to attach the trailingAnchor.
/// - constant: Constant size.
/// - Returns: Yourself.
public func pinTrailing(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
pinTrailing(anchor: anchor, constant: constant)
return self
}
@discardableResult
/// Adds a trailingAnchor to a specific XAxisAnchor passed in using a lessThanOrEqualTo Constraint
/// - Parameter anchor:The anchor in which to attach the trailingAnchor
/// - constant: Constant size.
/// - Returns: Yourself.
public func pinTrailingLessThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
pinTrailingLessThanOrEqualTo(anchor: anchor, constant: constant)
return self
}
@discardableResult
/// Adds a trailingAnchor to a specific XAxisAnchor passed in using a greaterThanOrEqualTo Constraint
/// - Parameter anchor:The anchor in which to attach the trailingAnchor
/// - constant: Constant size.
/// - Returns: Yourself.
public func pinTrailingGreaterThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self {
pinTrailingGreaterThanOrEqualTo(anchor: anchor, constant: constant)
return self
}
@discardableResult
/// Adds a trailingAnchor for the constant passed into the method.
/// - Parameter anchor:The anchor in which to attach the trailingAnchor
/// - constant: Constant size.
/// - Returns: The Constraint that was created.
public func pinTrailing(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutXAxisAnchor? = anchor ?? superview?.trailingAnchor
guard let found else { return nil }
return trailingAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
}
@discardableResult
/// Adds a trailingAnchor with the constant passed in using a lessThanOrEqualTo Constraint.
/// - Parameter anchor:The anchor in which to attach the trailingAnchor
/// - constant: Constant size.
/// - Returns: The Constraint that was created.
public func pinTrailingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutXAxisAnchor? = anchor ?? superview?.trailingAnchor
guard let found else { return nil }
return trailingAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
}
@discardableResult
/// Adds a trailingAnchor with the constant passed in using a greaterThanOrEqualTo Constraint.
/// - Parameter anchor:The anchor in which to attach the trailingAnchor
/// - constant: Constant size.
/// - Returns: The Constraint that was created.
public func pinTrailingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutXAxisAnchor? = anchor ?? superview?.trailingAnchor
guard let found else { return nil }
return trailingAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
}
}
extension NSLayoutConstraint { extension NSLayoutConstraint {
@discardableResult @discardableResult

View File

@ -1,5 +1,5 @@
// //
// NSLayoutGuide.swift // LayoutConstraintable.swift
// VDS // VDS
// //
// Created by Matt Bruce on 8/22/23. // Created by Matt Bruce on 8/22/23.
@ -7,12 +7,27 @@
import Foundation import Foundation
import UIKit import UIKit
import VDSFormControlsTokens
public protocol LayoutConstraintable {
var superview: UIView? { get }
var leadingAnchor: NSLayoutXAxisAnchor { get }
var trailingAnchor: NSLayoutXAxisAnchor { get }
var topAnchor: NSLayoutYAxisAnchor { get }
var bottomAnchor: NSLayoutYAxisAnchor { get }
var widthAnchor: NSLayoutDimension { get }
var heightAnchor: NSLayoutDimension { get }
var centerXAnchor: NSLayoutXAxisAnchor { get }
var centerYAnchor: NSLayoutYAxisAnchor { get }
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Pinning // MARK: - Pinning
//-------------------------------------------------- //--------------------------------------------------
extension UILayoutGuide { extension LayoutConstraintable {
@discardableResult @discardableResult
/// Pins each to the all 4 anchor points to a view. /// Pins each to the all 4 anchor points to a view.
/// - Parameters: /// - Parameters:
@ -32,9 +47,9 @@ extension UILayoutGuide {
/// Pins each to the all 4 anchor points to the view you are set within. /// Pins each to the all 4 anchor points to the view you are set within.
/// - Parameter edges: Insets for each side. /// - Parameter edges: Insets for each side.
/// - Returns: Yourself. /// - Returns: Yourself.
public func pinToOwningView(_ edges: UIEdgeInsets = UIEdgeInsets.zero) -> Self { public func pinToSuperView(_ edges: UIEdgeInsets = UIEdgeInsets.zero) -> Self {
if let owningView { if let superview {
pin(owningView, with: edges) pin(superview, with: edges)
} }
return self return self
} }
@ -43,7 +58,7 @@ extension UILayoutGuide {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - HeightAnchor // MARK: - HeightAnchor
//-------------------------------------------------- //--------------------------------------------------
extension UILayoutGuide { extension LayoutConstraintable {
@discardableResult @discardableResult
/// Adds a heightAnchor. /// Adds a heightAnchor.
@ -101,7 +116,7 @@ extension UILayoutGuide {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - WidthAnchor // MARK: - WidthAnchor
//-------------------------------------------------- //--------------------------------------------------
extension UILayoutGuide { extension LayoutConstraintable {
@discardableResult @discardableResult
/// Adds a widthAnchor. /// Adds a widthAnchor.
@ -158,7 +173,7 @@ extension UILayoutGuide {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - TopAnchor // MARK: - TopAnchor
//-------------------------------------------------- //--------------------------------------------------
extension UILayoutGuide { extension LayoutConstraintable {
@discardableResult @discardableResult
/// Adds a topAnchor. /// Adds a topAnchor.
@ -204,7 +219,7 @@ extension UILayoutGuide {
/// - constant: Constant size. /// - constant: Constant size.
/// - Returns: The Constraint that was created. /// - Returns: The Constraint that was created.
public func pinTop(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { public func pinTop(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.topAnchor let found: NSLayoutYAxisAnchor? = anchor ?? superview?.topAnchor
guard let found else { return nil } guard let found else { return nil }
return topAnchor.constraint(equalTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } return topAnchor.constraint(equalTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true }
} }
@ -215,7 +230,7 @@ extension UILayoutGuide {
/// - constant: Constant size. /// - constant: Constant size.
/// - Returns: The Constraint that was created. /// - Returns: The Constraint that was created.
public func pinTopLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { public func pinTopLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.topAnchor let found: NSLayoutYAxisAnchor? = anchor ?? superview?.topAnchor
guard let found else { return nil } guard let found else { return nil }
return topAnchor.constraint(lessThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } return topAnchor.constraint(lessThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true }
} }
@ -226,7 +241,7 @@ extension UILayoutGuide {
/// - constant: Constant size. /// - constant: Constant size.
/// - Returns: The Constraint that was created. /// - Returns: The Constraint that was created.
public func pinTopGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { public func pinTopGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.topAnchor let found: NSLayoutYAxisAnchor? = anchor ?? superview?.topAnchor
guard let found else { return nil } guard let found else { return nil }
return topAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } return topAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true }
} }
@ -236,7 +251,7 @@ extension UILayoutGuide {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - BottomAnchor // MARK: - BottomAnchor
//-------------------------------------------------- //--------------------------------------------------
extension UILayoutGuide { extension LayoutConstraintable {
@discardableResult @discardableResult
/// Adds a bottomAnchor. /// Adds a bottomAnchor.
/// - Parameter constant: Constant size. /// - Parameter constant: Constant size.
@ -281,7 +296,7 @@ extension UILayoutGuide {
/// - constant: Constant size. /// - constant: Constant size.
/// - Returns: The Constraint that was created. /// - Returns: The Constraint that was created.
public func pinBottom(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { public func pinBottom(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.bottomAnchor let found: NSLayoutYAxisAnchor? = anchor ?? superview?.bottomAnchor
guard let found else { return nil } guard let found else { return nil }
return bottomAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } return bottomAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
} }
@ -292,7 +307,7 @@ extension UILayoutGuide {
/// - constant: Constant size. /// - constant: Constant size.
/// - Returns: The Constraint that was created. /// - Returns: The Constraint that was created.
public func pinBottomLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { public func pinBottomLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.bottomAnchor let found: NSLayoutYAxisAnchor? = anchor ?? superview?.bottomAnchor
guard let found else { return nil } guard let found else { return nil }
return bottomAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } return bottomAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
} }
@ -303,7 +318,7 @@ extension UILayoutGuide {
/// - constant: Constant size. /// - constant: Constant size.
/// - Returns: The Constraint that was created. /// - Returns: The Constraint that was created.
public func pinBottomGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { public func pinBottomGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.bottomAnchor let found: NSLayoutYAxisAnchor? = anchor ?? superview?.bottomAnchor
guard let found else { return nil } guard let found else { return nil }
return bottomAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } return bottomAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
} }
@ -312,7 +327,7 @@ extension UILayoutGuide {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - LeadingAnchor // MARK: - LeadingAnchor
//-------------------------------------------------- //--------------------------------------------------
extension UILayoutGuide { extension LayoutConstraintable {
@discardableResult @discardableResult
/// Adds a leadingAnchor. /// Adds a leadingAnchor.
@ -358,7 +373,7 @@ extension UILayoutGuide {
/// - constant: Constant size. /// - constant: Constant size.
/// - Returns: The Constraint that was created. /// - Returns: The Constraint that was created.
public func pinLeading(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { public func pinLeading(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.leadingAnchor let found: NSLayoutXAxisAnchor? = anchor ?? superview?.leadingAnchor
guard let found else { return nil } guard let found else { return nil }
return leadingAnchor.constraint(equalTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } return leadingAnchor.constraint(equalTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true }
} }
@ -369,7 +384,7 @@ extension UILayoutGuide {
/// - constant: Constant size. /// - constant: Constant size.
/// - Returns: The Constraint that was created. /// - Returns: The Constraint that was created.
public func pinLeadingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { public func pinLeadingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.leadingAnchor let found: NSLayoutXAxisAnchor? = anchor ?? superview?.leadingAnchor
guard let found else { return nil } guard let found else { return nil }
return leadingAnchor.constraint(lessThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } return leadingAnchor.constraint(lessThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true }
} }
@ -380,7 +395,7 @@ extension UILayoutGuide {
/// - constant: Constant size. /// - constant: Constant size.
/// - Returns: The Constraint that was created. /// - Returns: The Constraint that was created.
public func pinLeadingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { public func pinLeadingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.leadingAnchor let found: NSLayoutXAxisAnchor? = anchor ?? superview?.leadingAnchor
guard let found else { return nil } guard let found else { return nil }
return leadingAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } return leadingAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true }
} }
@ -389,7 +404,7 @@ extension UILayoutGuide {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - TrailingAnchor // MARK: - TrailingAnchor
//-------------------------------------------------- //--------------------------------------------------
extension UILayoutGuide { extension LayoutConstraintable {
@discardableResult @discardableResult
/// Adds a trailingAnchor. /// Adds a trailingAnchor.
@ -435,7 +450,7 @@ extension UILayoutGuide {
/// - constant: Constant size. /// - constant: Constant size.
/// - Returns: The Constraint that was created. /// - Returns: The Constraint that was created.
public func pinTrailing(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { public func pinTrailing(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.trailingAnchor let found: NSLayoutXAxisAnchor? = anchor ?? superview?.trailingAnchor
guard let found else { return nil } guard let found else { return nil }
return trailingAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } return trailingAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
} }
@ -446,7 +461,7 @@ extension UILayoutGuide {
/// - constant: Constant size. /// - constant: Constant size.
/// - Returns: The Constraint that was created. /// - Returns: The Constraint that was created.
public func pinTrailingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { public func pinTrailingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.trailingAnchor let found: NSLayoutXAxisAnchor? = anchor ?? superview?.trailingAnchor
guard let found else { return nil } guard let found else { return nil }
return trailingAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } return trailingAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
} }
@ -457,8 +472,19 @@ extension UILayoutGuide {
/// - constant: Constant size. /// - constant: Constant size.
/// - Returns: The Constraint that was created. /// - Returns: The Constraint that was created.
public func pinTrailingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { public func pinTrailingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.trailingAnchor let found: NSLayoutXAxisAnchor? = anchor ?? superview?.trailingAnchor
guard let found else { return nil } guard let found else { return nil }
return trailingAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } return trailingAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
} }
} }
//--------------------------------------------------
// MARK: - Implementations
//--------------------------------------------------
extension UIView: LayoutConstraintable {}
extension UILayoutGuide: LayoutConstraintable {
public var superview: UIView? {
owningView
}
}