UIView

public extension UIView
  • Change layer’s background color

    Declaration

    Swift

    @discardableResult
    func layer(backgroundColor color: CGColor?) -> Self

    Parameters

    color

    You can use UIColor.colorName.cgColor to pass UIColor value

  • Change layer’s background color

    Declaration

    Swift

    @discardableResult
    func layer(backgroundColor color: UIColor?) -> Self
  • Change layer’s content’s gravity.

    Declaration

    Swift

    @discardableResult
    func layer(contentsGravity: CALayerContentsGravity) -> Self

    Parameters

    gravity

    Will be used as layer’s gravity.

  • Change layer’s corner radius.

    Declaration

    Swift

    @discardableResult
    func layer(cornerRadius: Float) -> Self

    Parameters

    radius

    value, defines corner radius.

  • Change layer’s border color.

    Declaration

    Swift

    @discardableResult
    func layer(borderColor: CGColor?) -> Self

    Parameters

    color

    use UIColor.colorName.cgColor to pass UIColor value.

  • Change layer’s border color.

    Declaration

    Swift

    @discardableResult
    func layer(borderColor: UIColor?) -> Self
  • Change layer’s border width.

    Declaration

    Swift

    @discardableResult
    func layer(borderWidth: Float) -> Self

    Parameters

    width

    Will be used as width value.

  • Change layer’s opacity

    Declaration

    Swift

    @discardableResult
    func layer(opacity: Float) -> Self

    Parameters

    value

    Will be used as opacity value.

  • Change layer’s isHidden value

    Declaration

    Swift

    @discardableResult
    func layer(isHidden: Bool) -> Self
  • Set masks to bounds value.

    Declaration

    Swift

    @discardableResult
    func layer(masksToBounds: Bool) -> Self
  • Set layer’s mask.

    Declaration

    Swift

    @discardableResult
    func layer(mask: @autoclosure () -> CALayer?) -> Self

    Parameters

    layer

    Allows to set existing type or create new one inside closure.

  • Set isDoubleSided parameter.

    Declaration

    Swift

    @discardableResult
    func layer(isDoubleSided: Bool) -> Self
  • Set masked corners value.

    Declaration

    Swift

    @available(iOS 11.0, *)
    @discardableResult
    func layer(maskedCorners: @autoclosure () -> CACornerMask) -> Self

    Parameters

    corners

    You can pass exisiting value or create it inside closure

  • Set layer’s shadow opacity.

    Declaration

    Swift

    @discardableResult
    func layer(shadowOpacity: Float) -> Self

    Parameters

    opacity

  • Change layer’s shadow color.

    Declaration

    Swift

    @discardableResult
    func layer(shadowColor: CGColor?) -> Self

    Parameters

    color

    Pass UIColor.colorName.cgColor to pass UIColor value

  • Change layer’s shadow color.

    Declaration

    Swift

    @discardableResult
    func layer(shadowColor: UIColor?) -> Self
  • Set layer’s shadow radius. Takes Float and converts it to CGFloat for programmer’s convenience

    Declaration

    Swift

    @discardableResult
    func layer(shadowRadius: Float) -> Self

    Parameters

    radius

  • Changes layer’s shadowOffset to given in parameter

    Declaration

    Swift

    @discardableResult
    func layer(shadowOffset: @autoclosure () -> CGSize) -> Self

    Parameters

    offset

    offset value, can be calculated using closure inside or just add ready one.

  • Set shadow path by passing existing object or use curly braces to create own one.

    Declaration

    Swift

    @discardableResult
    func layer(shadowPath: @autoclosure () -> CGPath?) -> Self

    Parameters

    path

  • Set layer’s allowsEdgeAntialiasing.

    Declaration

    Swift

    @discardableResult
    func layer(allowsEdgeAntialiasing: Bool) -> Self
  • Set layer’s allowsGroupOpacity.

    Declaration

    Swift

    @discardableResult
    func layer(allowsGroupOpacity: Bool) -> Self
  • Set layer’s style.

    Declaration

    Swift

    @discardableResult
    func layer(style: @autoclosure () -> [AnyHashable : Any]?) -> Self

    Parameters

    style

    You can pass exisiting value or create new one inside closure.

  • Set layer’s filters.

    Declaration

    Swift

    @discardableResult
    func layer(filters: @autoclosure () -> [Any]?) -> Self

    Parameters

    filters

    You can pass exisiting value or create new one inside closure.

  • Set layer’s isOpaque Boolean.

    Declaration

    Swift

    @discardableResult
    func layer(isOpaque: Bool) -> Self
  • Set layer’s drawsAsynchronously

    Declaration

    Swift

    @discardableResult
    func layer(drawsAsynchronously: Bool) -> Self
  • Add animation to a layer.

    Declaration

    Swift

    @discardableResult
    func layer(addAnimation animation: CAAnimation, forKey key: String?) -> Self

    Parameters

    key

    Key which allows to identify given animation.

    animation

    You can pass existing value or create it inside closure.

  • Remove layer’s animation specified by given key.

    Declaration

    Swift

    @discardableResult
    func layer(removeAnimationForKey key: String) -> Self

    Parameters

    key

    Key that’s assigned to animation.

  • Remove all existing layer’s animations.

    Declaration

    Swift

    @discardableResult
    func removeAllAnimationsFromLayer() -> Self
  • Modify the object’s layer

    Declaration

    Swift

    @discardableResult
    func layer(_ closure: (CALayer) -> Void) -> Self

    Parameters

    closure

    A trailing closure that receives itself.layer inside the closue

  • The leading constraints held by the view

    Declaration

    Swift

    var leadingConstraints: [NSLayoutConstraint] { get }
  • The trailing constraints held by the view

    Declaration

    Swift

    var trailingConstraints: [NSLayoutConstraint] { get }
  • The top constraints held by the view

    Declaration

    Swift

    var topConstraints: [NSLayoutConstraint] { get }
  • The bottom constraints held by the view

    Declaration

    Swift

    var bottomConstraints: [NSLayoutConstraint] { get }
  • The height constraints held by the view

    Declaration

    Swift

    var heightConstraints: [NSLayoutConstraint] { get }
  • The width constraints held by the view

    Declaration

    Swift

    var widthConstraints: [NSLayoutConstraint] { get }
  • Create a UIView using a chain of events with a centeredLoadingView

    Declaration

    Swift

    static func chain(
        link: Chain,
        update: @escaping (UIView) -> Void,
        centeredLoadingView: UIView? = nil
    ) -> UIView

    Parameters

    link

    A Chain of events that must be completed for the view to be shown

    update

    A closure to handle updating the view when the chain is completed

    centeredLoadingView

    A view to show while the chain is running (Default: nil)

  • Create a UIView using a chain of events with an embeddedLoadingView

    Declaration

    Swift

    static func chain(
        link: Chain,
        update: @escaping (UIView) -> Void,
        embeddedLoadingView: UIView
    ) -> UIView

    Parameters

    link

    A Chain of events that must be completed for the view to be shown

    update

    A closure to handle updating the view when the chain is completed

    embeddedLoadingView

    A view to show while the chain is running

  • Create a UIView using a backgrounded chain of events with a centeredLoadingView

    Declaration

    Swift

    static func background(
        link: Chain,
        update: @escaping (UIView) -> Void,
        centeredLoadingView: UIView? = nil
    ) -> UIView

    Parameters

    link

    A Chain of events that must be completed for the view to be shown

    update

    A closure to handle updating the view when the chain is completed

    centeredLoadingView

    A view to show while the chain is running (Default: nil)

  • Create a UIView using a backgrounded chain of events with an embeddedLoadingView

    Declaration

    Swift

    static func background(
        link: Chain,
        update: @escaping (UIView) -> Void,
        embeddedLoadingView: UIView
    ) -> UIView

    Parameters

    link

    A Chain of events that must be completed for the view to be shown

    update

    A closure to handle updating the view when the chain is completed

    embeddedLoadingView

    A view to show while the chain is running

  • Create a UIView with an embedded view inside

    Declaration

    Swift

    convenience init(
        withPadding padding: Float = 0,
        backgroundColor: UIColor? = .clear,
        _ closure: (() -> UIView)? = nil
    )

    Parameters

    withPadding

    The padding surrounding the embedded view (Default: 0)

    backgroundColor

    The color to set as the backgroundColor of the parent view (Default: .clear)

    closure

    A trailing closure that accepts a view which will be embedded (Default: nil)

  • Create a UIView with an embedded view inside

    Declaration

    Swift

    convenience init(
        withPadding padding: [Padding],
        backgroundColor: UIColor? = .clear,
        _ closure: (() -> UIView)? = nil
    )

    Parameters

    withPadding

    The Padding surrounding the embedded view

    backgroundColor

    The color to set as the backgroundColor of the parent view (Default: .clear)

    closure

    A trailing closure that accepts a view which will be embedded (Default: nil)

  • Embed a Stack

    Declaration

    Swift

    @discardableResult
    func stack(
        withSpacing spacing: Float = 0,
        padding: Float = 0,
        alignment: UIStackView.Alignment = .fill,
        distribution: UIStackView.Distribution = .fill,
        axis: NSLayoutConstraint.Axis,
        _ closure: () -> [UIView?]
    ) -> Self

    Parameters

    withSpacing

    The amount of spacing between each child view (Default: 0)

    padding

    The amount of space between this view and its parent view (Default: 0)

    alignment

    The layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment) (Default: .fill)

    distribution

    The layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution) (Default: .fill)

    axis

    Keys that specify a horizontal or vertical layout constraint between objects (source: NSLayoutConstraint.Axis)

    closure

    A trailing closure that accepts an array of views

  • Embed a Stack

    Declaration

    Swift

    @discardableResult
    func stack(
        withSpacing spacing: Float = 0,
        padding: [Padding],
        alignment: UIStackView.Alignment = .fill,
        distribution: UIStackView.Distribution = .fill,
        axis: NSLayoutConstraint.Axis,
        _ closure: () -> [UIView?]
    ) -> Self

    Parameters

    withSpacing

    The amount of spacing between each child view (Default: 0)

    padding

    The amount of space between this view and its parent view

    alignment

    The layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment) (Default: .fill)

    distribution

    The layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution) (Default: .fill)

    axis

    Keys that specify a horizontal or vertical layout constraint between objects (source: NSLayoutConstraint.Axis)

    closure

    A trailing closure that accepts an array of views

  • Embed a VStack

    Declaration

    Swift

    @discardableResult
    func vstack(
        withSpacing spacing: Float = 0,
        padding: Float = 0,
        alignment: UIStackView.Alignment = .fill,
        distribution: UIStackView.Distribution = .fill,
        _ closure: () -> [UIView?]
    ) -> Self

    Parameters

    withSpacing

    The amount of spacing between each child view (Default: 0)

    padding

    The amount of space between this view and its parent view (Default: 0)

    alignment

    The layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment) (Default: .fill)

    distribution

    The layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution) (Default: .fill)

    closure

    A trailing closure that accepts an array of views

  • Embed a VStack

    Declaration

    Swift

    @discardableResult
    func vstack(
        withSpacing spacing: Float = 0,
        padding: [Padding],
        alignment: UIStackView.Alignment = .fill,
        distribution: UIStackView.Distribution = .fill,
        _ closure: () -> [UIView?]
    ) -> Self

    Parameters

    withSpacing

    The amount of spacing between each child view (Default: 0)

    padding

    The amount of space between this view and its parent view

    alignment

    The layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment) (Default: .fill)

    distribution

    The layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution) (Default: .fill)

    closure

    A trailing closure that accepts an array of views

  • Embed a HStack

    Declaration

    Swift

    @discardableResult
    func hstack(
        withSpacing spacing: Float = 0,
        padding: Float = 0,
        alignment: UIStackView.Alignment = .fill,
        distribution: UIStackView.Distribution = .fill,
        _ closure: () -> [UIView?]
    ) -> Self

    Parameters

    withSpacing

    The amount of spacing between each child view (Default: 0)

    padding

    The amount of space between this view and its parent view (Default: 0)

    alignment

    The layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment) (Default: .fill)

    distribution

    The layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution) (Default: .fill)

    closure

    A trailing closure that accepts an array of views

  • Embed a HStack

    Declaration

    Swift

    @discardableResult
    func hstack(
        withSpacing spacing: Float = 0,
        padding: [Padding],
        alignment: UIStackView.Alignment = .fill,
        distribution: UIStackView.Distribution = .fill,
        _ closure: () -> [UIView?]
    ) -> Self

    Parameters

    withSpacing

    The amount of spacing between each child view (Default: 0)

    padding

    The amount of space between this view and its parent view

    alignment

    The layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment) (Default: .fill)

    distribution

    The layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution) (Default: .fill)

    closure

    A trailing closure that accepts an array of views

  • Embed a View to all anchors (top, bottom, leading, trailing)

    Declaration

    Swift

    @discardableResult
    func embed(
        withPadding padding: Float = 0,
        _ closure: () -> UIView
    ) -> Self

    Parameters

    withPadding

    The amount of space between the embedded view and this view (Default: 0)

    closure

    A trailing closure that accepts a view

  • Center a View

    Declaration

    Swift

    @discardableResult
    func center(_ closure: () -> UIView) -> Self

    Parameters

    closure

    A trailing closure that accepts a view

  • Embed a View to certain anchors (top, bottom, leading, trailing)

    Declaration

    Swift

    @discardableResult
    func embed(
        withPadding padding: [Padding],
        _ closure: () -> UIView
    ) -> Self

    Parameters

    withPadding

    The amount of space between the embedded view and this view

    closure

    A trailing closure that accepts a view

  • Sets the vertical setContentHuggingPriority

    Declaration

    Swift

    @discardableResult
    func setVertical(huggingPriority: UILayoutPriority) -> Self
  • Sets the horizontal setContentHuggingPriority

    Declaration

    Swift

    @discardableResult
    func setHorizontal(huggingPriority: UILayoutPriority) -> Self
  • Sets the vertical setContentCompressionResistancePriority

    Declaration

    Swift

    @discardableResult
    func setVertical(compressionResistance: UILayoutPriority) -> Self
  • Sets the horizontal setContentCompressionResistancePriority

    Declaration

    Swift

    @discardableResult
    func setHorizontal(compressionResistance: UILayoutPriority) -> Self
  • Clear all subviews from this view

    Declaration

    Swift

    @discardableResult
    func clear() -> Self
  • Embed this view inside another with some padding

    Declaration

    Swift

    @discardableResult
    func padding(_ padding: Float = 8) -> UIView

    Parameters

    padding

    The amount of space between this view and its parent view (Default: 8)

  • Set the height and width anchors to constant values (if nil it will not update the constraint)

    Declaration

    Swift

    @discardableResult
    func frame(height: Float? = nil, width: Float? = nil) -> Self

    Parameters

    height

    Value for the heightAnchor (Default: nil)

    width

    Value for the widthAnchor (Default: nil)

  • Update the height and width anchors to constant values (if nil it will not update the constraint)

    Declaration

    Swift

    @available(iOS 10.0, *)
    @discardableResult
    func update(
        height: Float? = nil,
        width: Float? = nil,
        animated: Bool = false
    ) -> Self

    Parameters

    height

    Value for the heightAnchor (Default: nil)

    width

    Value for the widthAnchor (Default: nil)

  • Update a padding anchor’s constant value

    Declaration

    Swift

    @available(iOS 10.0, *)
    @discardableResult
    func update(padding: Padding, animated: Bool = false) -> Self
  • Update an array of padding anchors’ constant values

    Declaration

    Swift

    @available(iOS 10.0, *)
    @discardableResult
    func update(padding: [Padding], animated: Bool = false) -> Self
  • Update all padding anchors’ constant value

    Declaration

    Swift

    @available(iOS 10.0, *)
    @discardableResult
    func update(padding: Float, animated: Bool = false) -> Self
  • Remove the height anchor constraint

    Declaration

    Swift

    @available(iOS 10.0, *)
    @discardableResult
    func removeHeightConstraint() -> Self
  • Remove the width anchor constraint

    Declaration

    Swift

    @available(iOS 10.0, *)
    @discardableResult
    func removeWidthConstraint() -> Self
  • Activate LayoutConstraints

    Declaration

    Swift

    @discardableResult
    func activateLayoutConstraints(_ constraints: () -> [NSLayoutConstraint]) -> Self

    Parameters

    constraints

    A trailing closure that accepts an array of NSLayoutConstraint

  • Offset the View’s center by (x, y)

    Declaration

    Swift

    @discardableResult
    func offset(x: Float? = nil, y: Float? = nil) -> Self

    Parameters

    x

    Value to add to the center.x (Default: nil)

    y

    Value to add to the center.y (Default: nil)

  • Set the View’s center to (x, y)

    Declaration

    Swift

    @discardableResult
    func center(x: Float? = nil, y: Float? = nil) -> Self

    Parameters

    x

    Value to set the center.x (Default: nil)

    y

    Value to set the center.y (Default: nil)

  • Constrains the View’s centerAnchors

    Declaration

    Swift

    @discardableResult
    func center(
        xOffset: Float? = nil,
        yOffset: Float? = nil,
        in view: UIView
    ) -> Self
  • Animate the current view

    Declaration

    Swift

    @discardableResult
    func animate(
        withDuration duration: TimeInterval,
        animation: @escaping (UIView) -> Void,
        completion: ((UIView) -> Void)? = nil
    ) -> Self

    Parameters

    withDuration

    Duration of the animation

    animation

    Closure which changes to the view are animated

    completion

    Closure which runs once the animation has been completed (Default: nil)

  • Animate the current view

    Declaration

    Swift

    @discardableResult
    func animate(
        withDuration duration: TimeInterval,
        delay: TimeInterval,
        options: UIView.AnimationOptions,
        animation: @escaping (UIView) -> Void,
        completion: ((UIView) -> Void)? = nil
    ) -> Self

    Parameters

    withDuration

    Duration of the animation

    delay

    The duration which the animation should be delayed

    otions

    The UIView.AnimationOptions for the animation

    animation

    Closure which changes to the view are animated

    completion

    Closure which runs once the animation has been completed (Default: nil)

  • Hide the view

    Declaration

    Swift

    @discardableResult
    func hide(if shouldHide: Bool) -> Self

    Parameters

    if

    A bool that determines if the view should be hidden

  • Hide the view

    Declaration

    Swift

    @discardableResult
    func hide(if shouldHide: () -> Bool) -> Self

    Parameters

    if

    A closure that determines if the view should be hidden

  • Hide the view

    Declaration

    Swift

    @discardableResult
    func hidden(withAnimatedDuration duration: Double = 0) -> Self
  • Show the view

    Declaration

    Swift

    @discardableResult
    func appear(withAnimatedDuration duration: Double = 0) -> Self
  • Modify the transform of the view

    Declaration

    Swift

    @discardableResult
    func transform(_ closure: (CGAffineTransform) -> CGAffineTransform) -> Self
  • Sets the accessibility values of the view

    Declaration

    Swift

    @discardableResult
    func accessibility(
        label: String? = nil,
        identifier: String? = nil,
        traits: UIAccessibilityTraits? = nil
    ) -> Self
  • Add a GestureRecognizer to the view

    Declaration

    Swift

    @discardableResult
    func gesture(_ closure: () -> UIGestureRecognizer) -> Self

    Parameters

    closure

    A trailing closure that accepts a UIGestureRecognizer

  • Sets the backgroundColor of the view to the color provided

    Declaration

    Swift

    @discardableResult
    func background(color: UIColor?) -> Self
  • Sets clipsToBounds to the value provided

    Declaration

    Swift

    @discardableResult
    func clipsToBounds(_ shouldClip: Bool = true) -> Self
  • Configure the Navigate Singleton with the Root Navigation Controller

    Declaration

    Swift

    @discardableResult
    func navigateConfigure(controller: UINavigationController?) -> Self
  • Set the visibleViewController’s title

    Declaration

    Swift

    @discardableResult
    func navigateSet(title: String) -> Self

    Parameters

    title

    The title of the currentViewController

  • Set the left barButton

    Declaration

    Swift

    @discardableResult
    func navigateSetLeft(barButton: UIBarButtonItem?, animated: Bool = true) -> Self

    Parameters

    barButton

    The UIBarButtonItem to be set

    animated

    Should animate setting the left UIBarButtonItem (Default: true)

  • Set the right barButton

    Declaration

    Swift

    @discardableResult
    func navigateSetRight(barButton: UIBarButtonItem?, animated: Bool = true) -> Self

    Parameters

    barButton

    The UIBarButtonItem to be set

    animated

    Should animate setting the right UIBarButtonItem (Default: true)

  • Set the left barButtons

    Declaration

    Swift

    @discardableResult
    func navigateSetLeft(barButtons: [UIBarButtonItem]?, animated: Bool = true) -> Self

    Parameters

    barButton

    The [UIBarButtonItem] to be set

    animated

    Should animate setting the left UIBarButtonItem

  • Set the right barButtons

    Declaration

    Swift

    @discardableResult
    func navigateSetRight(barButtons: [UIBarButtonItem]?, animated: Bool = true) -> Self

    Parameters

    barButton

    The [UIBarButtonItem] to be set

    animated

    Should animate setting the right UIBarButtonItem

  • Returns all subviews of the current view

    Declaration

    Swift

    var allSubviews: [UIView] { get }
  • Useful debug function to change all subviews background color to a random color and count the number of subviews

    Declaration

    Swift

    @discardableResult
    func debug() -> Self