Skip to content

Add constrainCenter auto layout extension to UIView #9

Closed
@mpospese

Description

@mpospese

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

  1. struct Center which is an OptionSet (type Uint). It should have the following values:
    a. x = 1 << 0
    b. y = 1 << 1
    c. all = [.x, .y]
  2. method constrainCenter takes the following parameters:
    a. _ center: Center = .all
    b. to view2: Anchorable? = nil
    c. offset: UIOffset = .zero
    d. priority: UILayoutPriority = .required
    e. isActive: Bool = true
    This method creates centerX and/or centerY constraints using constrain anchor overrides (so .centerXAnchor and .centerYAnchor) and returns the one or two created constraints in a dictionary keyed by .centerX and/or .centerY, respectively. The result is discardable. When view2 == nil pass superview to constrain anchor (see otherView in UIView+constrainEdges.swift implementation). Generally refer to constrainEdges implementation as it will be similar only you are creating up to two constraints instead of up to four.
  3. Create a new XCTest file under Tests/YCoreUITests/Extensions/UIKit named UIView+constrainCenterTests.swift
    a. name the test UIViewContrainCenterTests and mark it final
    b. add three test cases to test creating only center x, only center y, and both.
  4. Ensure that all public interfaces 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