Add `constrainSize` auto layout extension to UIView
mpospese opened this issue · comments
Mark Pospesel commented
Create a new source file under Sources/YCoreUI/Extensions/UIKit
named UIView+constrainSize.swift
Publicly extend UIView
to add the following three methods:
constrainSize
takes parameters_ size: CGSize, relatedBy relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required, isActive: Bool = true
and returns a dictionary[NSLayoutConstraint.Attribute: NSLayoutConstraint]
a. creates width and height constraints usingconstrain
anchor overrides (so.widthAnchor
and.heightAnchor
)
b. returns the two created constraints in a dictionary keyed by.width
and.height
, respectively.
c. result is discardableconstrainSize
takes parameterswidth: CGFloat, height: CGFloat, relatedBy relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required, isActive: Bool = true
and returns same dictionary as 1.
a. creates a CGSize using width and height and then calls the override from 1.constrainSize
takes parameter_ dimension: CGFloat, relatedBy relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required, isActive: Bool = true
and returns same dictionary as 1.
a. creates a CGSize where width and height both equal dimension and then calls the override from 1.- Create a new XCTest file under
Tests/YCoreUITests/Extensions/UIKit
namedUIView+constrainSizeTests.swift
a. name the testUIViewContrainSizeTests
and mark itfinal
b. add test case for each of the three methods created above. - Ensure that the three new methods are fully documented with documentation comments (including parameters and returns)
Mark Pospesel commented
Usage:
let mySize: CGSize
imageView.pinSize(mySize)
otherView.pinSize(width: 320, height: 480)
tinyButton.pinSize(44) // 44 x 44