Add `constrainAspectRatio` auto layout extension method to UIView
mpospese opened this issue · comments
Mark Pospesel commented
Create a new source file under Sources/YCoreUI/Extensions/UIKit
named UIView+constrainAspectRatio.swift
Publicly extend UIView
to add the following method:
constrainAspectRatio
takes parameters
a._ ratio: CGFloat
b.offset: CGFloat = 0
b.relatedBy relation: NSLayoutConstraint.Relation = .equal
c,priority: UILayoutPriority = .required
d,isActive: Bool = true
- it creates a constraint on the receiving view, constraining its widthAnchor to its heightAnchor using
ratio
as the multiplier and optionaloffset
as the constant. - it returns the single created
NSLayoutConstraint
but it is@discardableResult
- Create a new XCTest file under
Tests/YCoreUITests/Extensions/UIKit
namedUIView+constrainAspectRatioTests.swift
a. name the testUIViewContrainAspectRatioTests
and mark itfinal
b. add test case for the method created above. - Ensure that the new method is fully documented with documentation comments (including parameters and returns)
- Add file comment example of how to set the aspect ratio of an image view (see
UIView+constrainAnchor.swift
Use-case examples) - Add same example to README
- Add same example to Notion page: https://www.notion.so/ymedialabs/Y-CoreUI-882275f4b88a408dba83f93539433d44