UIView

extension UIView
  • UIView animation without the long variable names

    Declaration

    Swift

    public class func animate(_ duration: TimeInterval,
                                 _ delay: TimeInterval,
                               _ damping: CGFloat,
                              _ velocity: CGFloat,
                               _ options: UIView.AnimationOptions,
                            _ animations: @escaping () -> Void,
                            _ completion: @escaping (Bool) -> Void = { _ in })
  • UIView animation without the long variable names or completion block

    Declaration

    Swift

    public class func animate(_ duration: TimeInterval,
                                 _ delay: TimeInterval,
                               _ damping: CGFloat,
                              _ velocity: CGFloat,
                               _ options: UIView.AnimationOptions,
                            _ animations: @escaping () -> Void)
  • The frame size, not to be confused with the bounds size

    For more information on the difference between a view’s bounds and frame, see:

    Declaration

    Swift

    public var size: CGSize { get set }
  • The frame height, not to be confused with the bounds height

    For more information on the difference between a view’s bounds and frame, see:

    Declaration

    Swift

    public var height: CGFloat { get set }
  • The frame width, not to be confused with the bounds width

    For more information on the difference between a view’s bounds and frame, see:

    Declaration

    Swift

    public var width: CGFloat { get set }
  • The frame origin, not to be confused with the bounds origin

    For more information on the difference between a view’s bounds and frame, see:

    Declaration

    Swift

    public var origin: CGPoint { get set }
  • The frame origin.x, not to be confused with the bounds origin.x

    For more information on the difference between a view’s bounds and frame, see:

    Declaration

    Swift

    public var originX: CGFloat { get set }
  • The frame origin.y, not to be confused with the bounds origin.y

    For more information on the difference between a view’s bounds and frame, see:

    Declaration

    Swift

    public var originY: CGFloat { get set }
  • The frame maxY, not to be confused with the bounds maxY

    For more information on the difference between a view’s bounds and frame, see:

    Declaration

    Swift

    public var maxY: CGFloat { get set }
  • The frame maxX, not to be confused with the bounds maxX

    For more information on the difference between a view’s bounds and frame, see:

    Declaration

    Swift

    public var maxX: CGFloat { get set }
  • The frame minY, not to be confused with the bounds minY

    For more information on the difference between a view’s bounds and frame, see:

    Declaration

    Swift

    public var minY: CGFloat { get set }
  • The frame minX, not to be confused with the bounds minX

    For more information on the difference between a view’s bounds and frame, see:

    Declaration

    Swift

    public var minX: CGFloat { get set }
  • The frame center.x, not to be confused with the bounds center.x

    For more information on the difference between a view’s bounds and frame, see:

    Declaration

    Swift

    public var centerX: CGFloat { get set }
  • The frame center.y, not to be confused with the bounds center.y

    For more information on the difference between a view’s bounds and frame, see:

    Declaration

    Swift

    public var centerY: CGFloat { get set }
  • The midpoint of the view’s bounds

    Implementation:

    return CGPoint(x: bounds.width/2, y: bounds.height/2)

    Declaration

    Swift

    public var boundsCenter: CGPoint { get }
  • Creates a UIImage representation of the view

    Declaration

    Swift

    public func snapshot() -> UIImage?
  • Constrain the current view to another view.

    Declaration

    Swift

    @discardableResult
    public func constrain(_ attribute: NSLayoutConstraint.Attribute,
                           _ relation: NSLayoutConstraint.Relation = .equal,
                         to otherView: UIView,
                     _ otherAttribute: NSLayoutConstraint.Attribute,
                     times multiplier: CGFloat = 1,
                        plus constant: CGFloat = 0,
                  atPriority priority: UILayoutPriority = .required,
                           identifier: String? = nil) -> NSLayoutConstraint

    Parameters

    attribute

    The layout attribute of self to constrain.

    relation

    The layout relation of self (optional, defaults to .Equal).

    otherView

    The other view to be constrained to.

    otherAttribute

    The layout attribute for the other view.

    multiplier

    The multiplier to use for the constraint (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    identifier

    The identifier for the constraint (optional).

    Return Value

    The created constraint for self.

  • Constrain the current view to a layout support such as topLayoutGuide or bottomLayoutGuide.

    Declaration

    Swift

    @discardableResult
    public func constrain(_ attribute: NSLayoutConstraint.Attribute,
                           _ relation: NSLayoutConstraint.Relation = .equal,
                    toSupport support: UILayoutSupport,
                     _ otherAttribute: NSLayoutConstraint.Attribute,
                     times multiplier: CGFloat = 1,
                        plus constant: CGFloat = 0,
                  atPriority priority: UILayoutPriority = .required,
                           identifier: String? = nil) -> NSLayoutConstraint

    Parameters

    attribute

    The layout attribute of self to constrain.

    relation

    The layout relation of self (optional, defaults to .Equal).

    support

    The support to be constrained to.

    otherAttribute

    The layout attribute for the support.

    multiplier

    The multiplier to use for the constraint (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    identifier

    The identifier for the constraint (optional).

    Return Value

    The created constraint for self.

  • Constrain the current view to a layout guide such as safeAreaLayoutGuide or layoutMarginsGuide.

    Declaration

    Swift

    @available(iOS 9.0, *)
    @discardableResult
    public func constrain(_ attribute: NSLayoutConstraint.Attribute,
                          _ relation: NSLayoutConstraint.Relation = .equal,
                          toGuide guide: UILayoutGuide,
                          _ otherAttribute: NSLayoutConstraint.Attribute,
                          times multiplier: CGFloat = 1,
                          plus constant: CGFloat = 0,
                          atPriority priority: UILayoutPriority = .required,
                          identifier: String? = nil) -> NSLayoutConstraint

    Parameters

    attribute

    The layout attribute of self to constrain.

    relation

    The layout relation of self (optional, defaults to .Equal).

    guide

    The guide to be constrained to.

    otherAttribute

    The layout attribute for the support.

    multiplier

    The multiplier to use for the constraint (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    identifier

    The identifier for the constraint (optional).

    Return Value

    The created constraint for self.

  • Constrain an attribute of the current view.

    Declaration

    Swift

    @discardableResult
    public func constrain(_ attribute: NSLayoutConstraint.Attribute,
                           _ relation: NSLayoutConstraint.Relation = .equal,
                          to constant: CGFloat,
                     times multiplier: CGFloat = 1,
                  atPriority priority: UILayoutPriority = .required,
                           identifier: String? = nil) -> NSLayoutConstraint

    Parameters

    attribute

    The layout attribute of self to constrain.

    relation

    The layout relation of self (optional, defaults to .Equal).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    multiplier

    The multiplier to use for the constraint (optional, defaults to 1).

    priority

    The priority for the constraint (optional, defaults to .required).

    identifier

    The identifier for the constraint (optional).

    Return Value

    The created constraint for self.

  • Constrain the edges of self its superview, with optional insets.

    Declaration

    Swift

    @discardableResult
    public func constrainEdgesToSuperview(top: CGFloat = 0, leading: CGFloat = 0, bottom: CGFloat = 0, trailing: CGFloat = 0) -> (top: NSLayoutConstraint, leading: NSLayoutConstraint, bottom: NSLayoutConstraint, trailing: NSLayoutConstraint)

    Parameters

    top

    The top insets (optional, defaults to 0).

    leading

    The leading insets (optional, defaults to 0).

    bottom

    The bottom insets (optional, defaults to 0).

    trailing

    The trailing insets (optional, defaults to 0).

    Return Value

    All four created constraints (top, leading, bottom, and trailing edges) for self.

  • Constrain the width of the current view.

    Declaration

    Swift

    @discardableResult
    public func constrainWidth(to value: CGFloat,
                             _ relation: NSLayoutConstraint.Relation = .equal,
                       times multiplier: CGFloat = 1,
                    atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    value

    The width value.

    relation

    The layout relation of self (optional, defaults to .Equal).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the height of the current view.

    Declaration

    Swift

    @discardableResult
    public func constrainHeight(to value: CGFloat,
                              _ relation: NSLayoutConstraint.Relation = .equal,
                        times multiplier: CGFloat = 1,
                     atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    value

    The height value.

    relation

    The layout relation of self (optional, defaults to .Equal).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the width of the current view to another view.

    Declaration

    Swift

    @discardableResult
    public func constrainWidth(to view: UIView,
                           _ attribute: NSLayoutConstraint.Attribute = .width,
                              relation: NSLayoutConstraint.Relation = .equal,
                      times multiplier: CGFloat = 1,
                         plus constant: CGFloat = 0,
                   atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    view

    The view by which to constrain self

    attribute

    The layout attribute of self to constrain (optional, defaults to .Width).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the height of the current view to another view.

    Declaration

    Swift

    @discardableResult
    public func constrainHeight(to view: UIView,
                            _ attribute: NSLayoutConstraint.Attribute = .height,
                               relation: NSLayoutConstraint.Relation = .equal,
                       times multiplier: CGFloat = 1,
                          plus constant: CGFloat = 0,
                    atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    view

    The view by which to constrain self

    attribute

    The layout attribute of self to constrain (optional, defaults to .Height).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the left constraint of the current view.

    Declaration

    Swift

    @discardableResult
    public func pinLeft(to view: UIView,
                    _ attribute: NSLayoutConstraint.Attribute = .left,
                       relation: NSLayoutConstraint.Relation = .equal,
               times multiplier: CGFloat = 1,
                  plus constant: CGFloat = 0,
            atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    view

    The view by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Left).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the right constraint of the current view.

    Declaration

    Swift

    @discardableResult
    public func pinRight(to view: UIView,
                     _ attribute: NSLayoutConstraint.Attribute = .right,
                        relation: NSLayoutConstraint.Relation = .equal,
                times multiplier: CGFloat = 1,
                   plus constant: CGFloat = 0,
             atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    view

    The view by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Right).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the top constraint of the current view.

    Declaration

    Swift

    @discardableResult
    public func pinTop(to view: UIView,
                   _ attribute: NSLayoutConstraint.Attribute = .top,
                      relation: NSLayoutConstraint.Relation = .equal,
              times multiplier: CGFloat = 1,
                 plus constant: CGFloat = 0,
           atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    view

    The view by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Top).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the bottom constraint of the current view.

    Declaration

    Swift

    @discardableResult
    public func pinBottom(to view: UIView,
                      _ attribute: NSLayoutConstraint.Attribute = .bottom,
                         relation: NSLayoutConstraint.Relation = .equal,
                 times multiplier: CGFloat = 1,
                    plus constant: CGFloat = 0,
              atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    view

    The view by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Bottom).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the leading constraint of the current view.

    Declaration

    Swift

    @discardableResult
    public func pinLeading(to view: UIView,
                       _ attribute: NSLayoutConstraint.Attribute = .leading,
                          relation: NSLayoutConstraint.Relation = .equal,
                  times multiplier: CGFloat = 1,
                     plus constant: CGFloat = 0,
               atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    view

    The view by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Leading).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the trailing constraint of the current view.

    Declaration

    Swift

    @discardableResult
    public func pinTrailing(to view: UIView,
                        _ attribute: NSLayoutConstraint.Attribute = .trailing,
                           relation: NSLayoutConstraint.Relation = .equal,
                   times multiplier: CGFloat = 1,
                      plus constant: CGFloat = 0,
                atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    view

    The view by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Trailing).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the center X constraint of the current view.

    Declaration

    Swift

    @discardableResult
    public func pinCenterX(to view: UIView,
                       _ attribute: NSLayoutConstraint.Attribute = .centerX,
                          relation: NSLayoutConstraint.Relation = .equal,
                  times multiplier: CGFloat = 1,
                     plus constant: CGFloat = 0,
               atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    view

    The view by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .CenterX).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the center Y constraint of the current view.

    Declaration

    Swift

    @discardableResult
    public func pinCenterY(to view: UIView,
                       _ attribute: NSLayoutConstraint.Attribute = .centerY,
                          relation: NSLayoutConstraint.Relation = .equal,
                  times multiplier: CGFloat = 1,
                     plus constant: CGFloat = 0,
               atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    view

    The view by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .CenterY).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain self to fit its content for the specified layout constraint axes.

    Declaration

    Swift

    public func constrainSize(toFit axes: NSLayoutConstraint.Axis..., priority: UILayoutPriority = .required)

    Parameters

    axes

    The axes on which to constrain self (variadic).

    priority

    The layout priority for content hugging and compression (optional, defaults to .required)

  • Add self to a superview.

    Declaration

    Swift

    @discardableResult
    @nonobjc
    public func add(toSuperview superview: UIView) -> Self

    Parameters

    toSuperview

    The superview in which to add self.

  • Add self as an arranged subview of a UIStackView.

    Declaration

    Swift

    @available(iOS 9.0, *)
    @discardableResult
    public func add(toStackview stackview: UIStackView) -> Self

    Parameters

    toStackview

    The stackview in which to add self as an arranged subview.

  • Returns a UIView object that has been added as a subview to the given superview.

    Declaration

    Swift

    public convenience init(superview: UIView)

    Parameters

    superview

    The view in which to add self as a subview.

    Return Value

    A UIView initialized and added as a subview to the given superview.

  • Take a snapshot of the given view, adding it to self which is treated as the canvas-view. Will place the snapshot view within self (canvas view) at the snapshotted view’s same position on screen.

    let snapshot = canvas.addSnapshotOfView(view, afterUpdates: false)

    Declaration

    Swift

    @nonobjc
    public func addSnapshot(of view: UIView, afterUpdates: Bool = false) -> UIView?

    Parameters

    view

    The view to snapshot

    afterUpdates

    A Boolean value (default: false) that specifies whether the snapshot should be taken after recent changes have been incorporated. Pass the value false to capture the screen in its current state, which might not include recent changes.

    Return Value

    The snapshotted view (already added to the caller).

  • Convenience for calling addSnapshotOfView(_:afterUpdates:) over an array of views.

    Declaration

    Swift

    @nonobjc
    public func addSnapshot(of views: [UIView], afterUpdates: Bool = false) -> [UIView]

    Parameters

    views

    The views to snapshot.

    afterUpdates

    A Boolean value (default: false) that specifies whether the snapshot should be taken after recent changes have been incorporated. Pass the value false to capture the screen in its current state, which might not include recent changes.

    Return Value

    The snapshotted views.

  • Constrain the left constraint of the current view.

    Declaration

    Swift

    @discardableResult
    @nonobjc
    public func pinLeft(to support: UILayoutSupport,
                           _ attribute: NSLayoutConstraint.Attribute = .left,
                             relation: NSLayoutConstraint.Relation = .equal,
                             times multiplier: CGFloat = 1,
                                   plus constant: CGFloat = 0,
                                        atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    support

    The support by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Left).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the right constraint of the current view.

    Declaration

    Swift

    @discardableResult
    @nonobjc
    public func pinRight(to support: UILayoutSupport,
                            _ attribute: NSLayoutConstraint.Attribute = .right,
                              relation: NSLayoutConstraint.Relation = .equal,
                              times multiplier: CGFloat = 1,
                                    plus constant: CGFloat = 0,
                                         atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    support

    The support by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Right).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the top constraint of the current view.

    Declaration

    Swift

    @discardableResult
    @nonobjc
    public func pinTop(to support: UILayoutSupport,
                          _ attribute: NSLayoutConstraint.Attribute = .top,
                            relation: NSLayoutConstraint.Relation = .equal,
                            times multiplier: CGFloat = 1,
                                  plus constant: CGFloat = 0,
                                       atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    support

    The support by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Top).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the bottom constraint of the current view.

    Declaration

    Swift

    @discardableResult
    @nonobjc
    public func pinBottom(to support: UILayoutSupport,
                             _ attribute: NSLayoutConstraint.Attribute = .bottom,
                               relation: NSLayoutConstraint.Relation = .equal,
                               times multiplier: CGFloat = 1,
                                     plus constant: CGFloat = 0,
                                          atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    support

    The support by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Bottom).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the leading constraint of the current view.

    Declaration

    Swift

    @discardableResult
    @nonobjc
    public func pinLeading(to support: UILayoutSupport,
                              _ attribute: NSLayoutConstraint.Attribute = .leading,
                                relation: NSLayoutConstraint.Relation = .equal,
                                times multiplier: CGFloat = 1,
                                      plus constant: CGFloat = 0,
                                           atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    support

    The support by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Leading).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the trailing constraint of the current view.

    Declaration

    Swift

    @discardableResult
    @nonobjc
    public func pinTrailing(to support: UILayoutSupport,
                               _ attribute: NSLayoutConstraint.Attribute = .trailing,
                                 relation: NSLayoutConstraint.Relation = .equal,
                                 times multiplier: CGFloat = 1,
                                       plus constant: CGFloat = 0,
                                            atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    support

    The support by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Trailing).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the center X constraint of the current view.

    Declaration

    Swift

    @discardableResult
    @nonobjc
    public func pinCenterX(to support: UILayoutSupport,
                              _ attribute: NSLayoutConstraint.Attribute = .centerX,
                                relation: NSLayoutConstraint.Relation = .equal,
                                times multiplier: CGFloat = 1,
                                      plus constant: CGFloat = 0,
                                           atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    support

    The support by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .CenterX).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the center Y constraint of the current view.

    Declaration

    Swift

    @discardableResult
    @nonobjc
    public func pinCenterY(to support: UILayoutSupport,
                              _ attribute: NSLayoutConstraint.Attribute = .centerY,
                                relation: NSLayoutConstraint.Relation = .equal,
                                times multiplier: CGFloat = 1,
                                      plus constant: CGFloat = 0,
                                           atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    support

    The support by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .CenterY).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the left constraint of the current view.

    Declaration

    Swift

    @available(iOS 9.0, *)
    @discardableResult
    @nonobjc
    public func pinLeft(to guide: UILayoutGuide,
                        _ attribute: NSLayoutConstraint.Attribute = .left,
                        relation: NSLayoutConstraint.Relation = .equal,
                        times multiplier: CGFloat = 1,
                        plus constant: CGFloat = 0,
                        atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    guide

    The guide by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Left).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the right constraint of the current view.

    Declaration

    Swift

    @available(iOS 9.0, *)
    @discardableResult
    @nonobjc
    public func pinRight(to guide: UILayoutGuide,
                         _ attribute: NSLayoutConstraint.Attribute = .right,
                         relation: NSLayoutConstraint.Relation = .equal,
                         times multiplier: CGFloat = 1,
                         plus constant: CGFloat = 0,
                         atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    guide

    The guide by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Right).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the top constraint of the current view.

    Declaration

    Swift

    @available(iOS 9.0, *)
    @discardableResult
    @nonobjc
    public func pinTop(to guide: UILayoutGuide,
                       _ attribute: NSLayoutConstraint.Attribute = .top,
                       relation: NSLayoutConstraint.Relation = .equal,
                       times multiplier: CGFloat = 1,
                       plus constant: CGFloat = 0,
                       atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    guide

    The guide by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Top).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the bottom constraint of the current view.

    Declaration

    Swift

    @available(iOS 9.0, *)
    @discardableResult
    @nonobjc
    public func pinBottom(to guide: UILayoutGuide,
                          _ attribute: NSLayoutConstraint.Attribute = .bottom,
                          relation: NSLayoutConstraint.Relation = .equal,
                          times multiplier: CGFloat = 1,
                          plus constant: CGFloat = 0,
                          atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    guide

    The guide by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Bottom).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the leading constraint of the current view.

    Declaration

    Swift

    @available(iOS 9.0, *)
    @discardableResult
    @nonobjc
    public func pinLeading(to guide: UILayoutGuide,
                           _ attribute: NSLayoutConstraint.Attribute = .leading,
                           relation: NSLayoutConstraint.Relation = .equal,
                           times multiplier: CGFloat = 1,
                           plus constant: CGFloat = 0,
                           atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    guide

    The guide by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Leading).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the trailing constraint of the current view.

    Declaration

    Swift

    @available(iOS 9.0, *)
    @discardableResult
    @nonobjc
    public func pinTrailing(to guide: UILayoutGuide,
                            _ attribute: NSLayoutConstraint.Attribute = .trailing,
                            relation: NSLayoutConstraint.Relation = .equal,
                            times multiplier: CGFloat = 1,
                            plus constant: CGFloat = 0,
                            atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    guide

    The guide by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .Trailing).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the center X constraint of the current view.

    Declaration

    Swift

    @available(iOS 9.0, *)
    @discardableResult
    @nonobjc
    public func pinCenterX(to guide: UILayoutGuide,
                           _ attribute: NSLayoutConstraint.Attribute = .centerX,
                           relation: NSLayoutConstraint.Relation = .equal,
                           times multiplier: CGFloat = 1,
                           plus constant: CGFloat = 0,
                           atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    guide

    The guide by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .CenterX).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the center Y constraint of the current view.

    Declaration

    Swift

    @available(iOS 9.0, *)
    @discardableResult
    @nonobjc
    public func pinCenterY(to guide: UILayoutGuide,
                           _ attribute: NSLayoutConstraint.Attribute = .centerY,
                           relation: NSLayoutConstraint.Relation = .equal,
                           times multiplier: CGFloat = 1,
                           plus constant: CGFloat = 0,
                           atPriority priority: UILayoutPriority = .required) -> Self

    Parameters

    guide

    The guide by which to constrain self.

    attribute

    The layout attribute of self to constrain (optional, defaults to .CenterY).

    relation

    The layout relation of self (optional, defaults to .Equal).

    multiplier

    The constraint multiplier (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    Return Value

    self

  • Constrain the current view to the safeAreaLayoutGuide of another view.

    Note: If the target iOS version is less than 11.0, the view will be constrained directly to the other view, not that view’s safeAreaLayoutGuide.

    Declaration

    Swift

    @discardableResult
    public func pinSafely(
        _ attribute: NSLayoutConstraint.Attribute,
        _ relation: NSLayoutConstraint.Relation = .equal,
        to otherView: UIView,
        _ otherAttribute: NSLayoutConstraint.Attribute? = nil,
        times multiplier: CGFloat = 1,
        plus constant: CGFloat = 0,
        atPriority priority: UILayoutPriority = .required,
        identifier: String? = nil) -> Self

    Parameters

    attribute

    The layout attribute of self to constrain.

    relation

    The layout relation of self (optional, defaults to .Equal).

    otherView

    The other view to be constrained to.

    otherAttribute

    The layout attribute for the other view.

    multiplier

    The multiplier to use for the constraint (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    identifier

    The identifier for the constraint (optional).

    Return Value

    self

  • Constrain the current view to the safeAreaLayoutGuide of another view.

    Note: If the target iOS version is less than 11.0, the view will be constrained directly to the other view, not that view’s safeAreaLayoutGuide.

    Declaration

    Swift

    @discardableResult
    public func constrainSafely(_ attribute: NSLayoutConstraint.Attribute,
                         _ relation: NSLayoutConstraint.Relation = .equal,
                         to otherView: UIView,
                         _ otherAttribute: NSLayoutConstraint.Attribute? = nil,
                         times multiplier: CGFloat = 1,
                         plus constant: CGFloat = 0,
                         atPriority priority: UILayoutPriority = .required,
                         identifier: String? = nil) -> NSLayoutConstraint

    Parameters

    attribute

    The layout attribute of self to constrain.

    relation

    The layout relation of self (optional, defaults to .Equal).

    otherView

    The other view to be constrained to.

    otherAttribute

    The layout attribute for the other view.

    multiplier

    The multiplier to use for the constraint (optional, defaults to 1).

    constant

    The constant to use for the constraint (optional, defaults to 0).

    priority

    The priority for the constraint (optional, defaults to .required).

    identifier

    The identifier for the constraint (optional).

    Return Value

    The created constraint for self.