Skip to content

Commit

Permalink
Use anchors in UIView extension methods (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinder-cfuller authored Mar 2, 2024
1 parent d0c590e commit 81ec821
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Sources/Layout/UIKit/UIView+AutoLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ extension UIView {
public func aspectRatioConstraint(
_ ratio: CGFloat
) -> NSLayoutConstraint {
constraint(for: .width, to: .height, of: self, multiplier: ratio)
width.constraint(to: height, multiplier: ratio)
}

// MARK: - Equal
Expand Down Expand Up @@ -184,9 +184,12 @@ extension UIView {
public func centerConstraints(
offset: UIOffset = .zero
) -> [NSLayoutConstraint] {
[
constraint(toSuperview: .centerX, constant: offset.horizontal),
constraint(toSuperview: .centerY, constant: offset.vertical)
assert(superview != nil, "centerConstraints(offset:) requires superview")
guard let superview: UIView
else { return [] }
return [
centerX.constraint(to: superview.centerX, constant: offset.horizontal),
centerY.constraint(to: superview.centerY, constant: offset.vertical)
]
}

Expand Down

0 comments on commit 81ec821

Please sign in to comment.