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) -> NSLayoutConstraintParameters
attributeThe layout attribute of self to constrain.
relationThe layout relation of self (optional, defaults to .Equal).
otherViewThe other view to be constrained to.
otherAttributeThe layout attribute for the other view.
multiplierThe multiplier to use for the constraint (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe priority for the constraint (optional, defaults to
.required).identifierThe identifier for the constraint (optional).
Return Value
The created constraint for self.
-
Constrain the current view to a layout support such as
topLayoutGuideorbottomLayoutGuide.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) -> NSLayoutConstraintParameters
attributeThe layout attribute of self to constrain.
relationThe layout relation of self (optional, defaults to .Equal).
supportThe support to be constrained to.
otherAttributeThe layout attribute for the support.
multiplierThe multiplier to use for the constraint (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe priority for the constraint (optional, defaults to
.required).identifierThe identifier for the constraint (optional).
Return Value
The created constraint for self.
-
Constrain the current view to a layout guide such as
safeAreaLayoutGuideorlayoutMarginsGuide.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) -> NSLayoutConstraintParameters
attributeThe layout attribute of self to constrain.
relationThe layout relation of self (optional, defaults to .Equal).
guideThe guide to be constrained to.
otherAttributeThe layout attribute for the support.
multiplierThe multiplier to use for the constraint (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe priority for the constraint (optional, defaults to
.required).identifierThe 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) -> NSLayoutConstraintParameters
attributeThe layout attribute of self to constrain.
relationThe layout relation of self (optional, defaults to .Equal).
constantThe constant to use for the constraint (optional, defaults to 0).
multiplierThe multiplier to use for the constraint (optional, defaults to 1).
priorityThe priority for the constraint (optional, defaults to
.required).identifierThe 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
topThe top insets (optional, defaults to 0).
leadingThe leading insets (optional, defaults to 0).
bottomThe bottom insets (optional, defaults to 0).
trailingThe 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) -> SelfParameters
valueThe width value.
relationThe layout relation of self (optional, defaults to .Equal).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
valueThe height value.
relationThe layout relation of self (optional, defaults to .Equal).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
viewThe view by which to constrain self
attributeThe layout attribute of self to constrain (optional, defaults to .Width).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
viewThe view by which to constrain self
attributeThe layout attribute of self to constrain (optional, defaults to .Height).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
viewThe view by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Left).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
viewThe view by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Right).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
viewThe view by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Top).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
viewThe view by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Bottom).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
viewThe view by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Leading).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
viewThe view by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Trailing).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
viewThe view by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .CenterX).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
viewThe view by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .CenterY).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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
axesThe axes on which to constrain self (variadic).
priorityThe 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) -> SelfParameters
toSuperviewThe 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) -> SelfParameters
toStackviewThe 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
superviewThe 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
selfwhich 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
viewThe view to snapshot
afterUpdatesA 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
viewsThe views to snapshot.
afterUpdatesA 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) -> SelfParameters
supportThe support by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Left).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
supportThe support by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Right).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
supportThe support by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Top).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
supportThe support by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Bottom).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
supportThe support by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Leading).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
supportThe support by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Trailing).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
supportThe support by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .CenterX).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
supportThe support by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .CenterY).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
guideThe guide by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Left).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
guideThe guide by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Right).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
guideThe guide by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Top).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
guideThe guide by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Bottom).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
guideThe guide by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Leading).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
guideThe guide by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .Trailing).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
guideThe guide by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .CenterX).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe 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) -> SelfParameters
guideThe guide by which to constrain self.
attributeThe layout attribute of self to constrain (optional, defaults to .CenterY).
relationThe layout relation of self (optional, defaults to .Equal).
multiplierThe constraint multiplier (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe priority for the constraint (optional, defaults to
.required).Return Value
self
-
Constrain the current view to the
safeAreaLayoutGuideof 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) -> SelfParameters
attributeThe layout attribute of self to constrain.
relationThe layout relation of self (optional, defaults to .Equal).
otherViewThe other view to be constrained to.
otherAttributeThe layout attribute for the other view.
multiplierThe multiplier to use for the constraint (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe priority for the constraint (optional, defaults to
.required).identifierThe identifier for the constraint (optional).
Return Value
self
-
Constrain the current view to the
safeAreaLayoutGuideof 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) -> NSLayoutConstraintParameters
attributeThe layout attribute of self to constrain.
relationThe layout relation of self (optional, defaults to .Equal).
otherViewThe other view to be constrained to.
otherAttributeThe layout attribute for the other view.
multiplierThe multiplier to use for the constraint (optional, defaults to 1).
constantThe constant to use for the constraint (optional, defaults to 0).
priorityThe priority for the constraint (optional, defaults to
.required).identifierThe identifier for the constraint (optional).
Return Value
The created constraint for self.
View on GitHub
Install in Dash
UIView Extension Reference