Skip to content

Commit

Permalink
Improve square and aspect ration implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
tinder-cfuller committed Feb 24, 2024
1 parent 2d96c85 commit 20f504d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions Sources/Layout/LayoutItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,17 @@ extension LayoutItem {
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
layoutItem.layoutItemView.widthConstraint(length).withPriority(priority)
layoutItem.layoutItemView.heightConstraint(length).withPriority(priority)
layoutItem.layoutItemView.squareConstraints(length).withPriority(priority)
}
}

/// Adds a constraint defining a square aspect ratio for the ``layoutItemView``.
///
/// - Returns: The layout item instance with the added constraint.
public func square() -> LayoutItem {
aspectRatio(1)
addingSuperviewConstraints { layoutItem in
layoutItem.layoutItemView.squareConstraint()
}
}

// MARK: - Aspect Ratio
Expand All @@ -256,9 +257,7 @@ extension LayoutItem {
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
layoutItem.layoutItemView
.constraint(for: .width, to: .height, of: layoutItem.layoutItemView, multiplier: ratio)
.withPriority(priority)
layoutItem.layoutItemView.aspectRatioConstraint(ratio).withPriority(priority)
}
}

Expand Down

0 comments on commit 20f504d

Please sign in to comment.