Skip to content

Add constrainAspectRatio auto layout extension method to UIView #34

Closed
@mpospese

Description

@mpospese

Create a new source file under Sources/YCoreUI/Extensions/UIKit named UIView+constrainAspectRatio.swift
Publicly extend UIView to add the following method:

  1. constrainAspectRatio takes parameters
    a. _ ratio: CGFloat
    b. offset: CGFloat = 0
    b. relatedBy relation: NSLayoutConstraint.Relation = .equal
    c, priority: UILayoutPriority = .required
    d, isActive: Bool = true
  2. it creates a constraint on the receiving view, constraining its widthAnchor to its heightAnchor using ratio as the multiplier and optional offset as the constant.
  3. it returns the single created NSLayoutConstraint but it is @discardableResult
  4. Create a new XCTest file under Tests/YCoreUITests/Extensions/UIKit named UIView+constrainAspectRatioTests.swift
    a. name the test UIViewContrainAspectRatioTests and mark it final
    b. add test case for the method created above.
  5. Ensure that the new method is fully documented with documentation comments (including parameters and returns)
  6. Add file comment example of how to set the aspect ratio of an image view (see UIView+constrainAnchor.swift Use-case examples)
  7. Add same example to README
  8. Add same example to Notion page: https://www.notion.so/ymedialabs/Y-CoreUI-882275f4b88a408dba83f93539433d44

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions