Skip to content

Add constrainSize auto layout extension to UIView #8

Closed
@mpospese

Description

@mpospese

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

  1. 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 using constrain anchor overrides (so .widthAnchor and .heightAnchor)
    b. returns the two created constraints in a dictionary keyed by .width and .height, respectively.
    c. result is discardable
  2. constrainSize takes parameters width: 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.
  3. 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.
  4. Create a new XCTest file under Tests/YCoreUITests/Extensions/UIKit named UIView+constrainSizeTests.swift
    a. name the test UIViewContrainSizeTests and mark it final
    b. add test case for each of the three methods created above.
  5. Ensure that the three new methods are fully documented with documentation comments (including parameters and returns)

Metadata

Metadata

Assignees

No one assigned

    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