UIView
class UIView : UIResponder, NSCoding, UIAppearance, UIAppearanceContainer, UIDynamicItem, UITraitEnvironment, UICoordinateSpace, UIFocusItem, UIFocusItemContainer, CALayerDelegate
-
A convenience method to align all edges of the view to the edges of another view. Note: this method does not use the ‘margin’ attributes, such as .topMargin, but uses the ‘edge’ attributes, such as .top
Declaration
Swift
@discardableResult public func rsd_alignAll(_ relation: NSLayoutConstraint.Relation, to view: UIView!, padding: CGFloat) -> [NSLayoutConstraint]Parameters
relationThe ‘NSLayoutRelation’ to apply to all constraints.
viewThe ‘UIView’ to which the view will be aligned.
paddingThe padding (or inset) to be applied to each constraint.
Return Value
The layout constraints that were added.
-
A convenience method to align all edges of the view to the edges of another view. Note: this method uses the ‘margin’ attributes, such as .topMargin, and not the ‘edge’ attributes, such as .top
Declaration
Swift
@discardableResult public func rsd_alignAllMargins(_ relation: NSLayoutConstraint.Relation, to view: UIView!, padding: CGFloat) -> [NSLayoutConstraint]Parameters
relationThe ‘NSLayoutRelation’ to apply to all constraints.
viewThe ‘UIView’ to which the view will be aligned.
paddingThe padding (or inset) to be applied to each constraint.
Return Value
The layout constraints that were added.
-
A convenience method to align an array of attributes of the view to the same attributes of it’s superview.
Declaration
Swift
@discardableResult public func rsd_alignToSuperview(_ attributes: [NSLayoutConstraint.Attribute], padding: CGFloat, priority: UILayoutPriority = UILayoutPriority(1000.0)) -> [NSLayoutConstraint]Parameters
attributeThe ‘NSLayoutAttribute’ to align to the view’s superview.
paddingThe padding (or inset) to be applied to the constraint.
Return Value
The layout constraints that were added.
-
A convenience method to align all edges of the view to the edges of its superview. Note: this method does not use the ‘margin’ attributes, such as .topMargin, but uses the ‘edge’ attributes, such as .top
Declaration
Swift
@discardableResult public func rsd_alignAllToSuperview(padding: CGFloat) -> [NSLayoutConstraint]Parameters
paddingThe padding (or inset) to be applied to each constraint.
Return Value
The layout constraints that were added.
-
A convenience method to align all edges of the view to the edges of its superview. Note: this method does not use the ‘margin’ attributes, such as .topMargin, but uses the ‘edge’ attributes, such as .top
Declaration
Swift
@discardableResult public func rsd_alignAllMarginsToSuperview(padding: CGFloat) -> [NSLayoutConstraint]Parameters
paddingThe padding (or inset) to be applied to each constraint.
Return Value
The layout constraints that were added.
-
A convenience method to position the view below another view.
Declaration
Swift
@discardableResult public func rsd_alignBelow(view: UIView, padding: CGFloat, priority: UILayoutPriority = UILayoutPriority(1000.0)) -> [NSLayoutConstraint]Parameters
viewThe ‘UIView’ to which the view will be aligned.
paddingThe padding (or inset) to be applied to the constraint.
Return Value
The layout constraints that were added.
-
A convenience method to position the view above another view.
Declaration
Swift
@discardableResult public func rsd_alignAbove(view: UIView, padding: CGFloat, priority: UILayoutPriority = UILayoutPriority(1000.0)) -> [NSLayoutConstraint]Parameters
viewThe ‘UIView’ to which the view will be aligned.
paddingThe padding (or inset) to be applied to the constraint.
Return Value
The layout constraints that were added.
-
A convenience method to position the view to the left of another view.
Declaration
Swift
@discardableResult public func rsd_alignLeftOf(view: UIView, padding: CGFloat, priority: UILayoutPriority = UILayoutPriority(1000.0)) -> [NSLayoutConstraint]Parameters
viewThe ‘UIView’ to which the view will be aligned.
paddingThe padding (or inset) to be applied to the constraint.
Return Value
The layout constraints that were added.
-
A convenience method to position the view to the right of another view.
Declaration
Swift
@discardableResult public func rsd_alignRightOf(view: UIView, padding: CGFloat, priority: UILayoutPriority = UILayoutPriority(1000.0)) -> [NSLayoutConstraint]Parameters
viewThe ‘UIView’ to which the view will be aligned.
paddingThe padding (or inset) to be applied to the constraint.
priorityThe layout priority of the constraint. By default, this is
1000.Return Value
The layout constraints that were added.
-
A convenience method to create a NSLayoutConstraint for the purpose of aligning views within their ‘superview’. As such, the view must have a ‘superview’.
Declaration
Swift
@discardableResult public func rsd_align(_ attributes: [NSLayoutConstraint.Attribute]!, _ relation: NSLayoutConstraint.Relation, to view: UIView!, _ toAttributes: [NSLayoutConstraint.Attribute]!, padding: CGFloat, priority: UILayoutPriority = UILayoutPriority(1000.0)) -> [NSLayoutConstraint]Parameters
attributesAn array of ‘NSLayoutAttribute’ to be applied to the ‘firstItem’ (self) in the constraints.
relationThe ‘NSLayoutRelation’ used for the constraint.
viewThe ‘UIView’ that the view is being constrained to.
toAttributesAn array of ‘NSLayoutAttribute’ to be applied to the ‘secondItem’ (to View) in the constraints.
paddingThe padding (or inset) to be applied to the constraints.
priorityThe layout priority of the constraint. By default, this is
1000.Return Value
The layout constraints that were added.
-
A convenience method to center the view vertically within its ‘superview’. The view must have a ‘superview’.
Declaration
Swift
@discardableResult public func rsd_alignCenterVertical(padding: CGFloat) -> [NSLayoutConstraint]Parameters
paddingThe padding (or offset from center) to be applied to the constraint.
Return Value
The layout constraints that were added.
-
A convenience method to center the view horizontally within it’s ‘superview’. The view must have a ‘superview’.
Declaration
Swift
@discardableResult public func rsd_alignCenterHorizontal(padding: CGFloat) -> [NSLayoutConstraint]Parameters
paddingThe padding (or offset from center) to be applied to the constraint.
Return Value
The layout constraints that were added.
-
A convenience method to constrain the view’s width.
Declaration
Swift
@discardableResult public func rsd_makeWidth(_ relation: NSLayoutConstraint.Relation, _ width: CGFloat, priority: UILayoutPriority = UILayoutPriority(1000.0)) -> [NSLayoutConstraint]Parameters
relationThe ‘NSLayoutRelation’ used in the constraint.
widthA ‘CGFloat’ constant for the width.
priorityThe layout priority of the constraint. By default, this is
1000.Return Value
The layout constraints that were added.
-
A convenience method to constrain the view’s height.
Declaration
Swift
@discardableResult public func rsd_makeHeight(_ relation: NSLayoutConstraint.Relation, _ height: CGFloat, priority: UILayoutPriority = UILayoutPriority(1000.0)) -> [NSLayoutConstraint]Parameters
relationThe ‘NSLayoutRelation’ used in the constraint.
heightA ‘CGFloat’ constant for the height.
priorityThe layout priority of the constraint. By default, this is
1000.Return Value
The layout constraints that were added.
-
A convenience method to constraint the view’s width relative to its superview.
Declaration
Swift
@discardableResult public func rsd_makeWidthEqualToSuperview(multiplier: CGFloat) -> [NSLayoutConstraint]Parameters
multiplierA
CGFloatconstant for the constraint multiplier.Return Value
The layout constraints that were added.
-
A convenience method to constrain the view’s height relative to its superview.
Declaration
Swift
@discardableResult public func rsd_makeHeightEqualToSuperview(multiplier: CGFloat) -> [NSLayoutConstraint]Parameters
multiplierA
CGFloatconstant for the constraint multiplier.Return Value
The layout constraints that were added.
-
A convenience method to constraint the view’s width relative to its superview.
Declaration
Swift
@discardableResult public func rsd_makeWidthEqualToView(_ view: UIView) -> [NSLayoutConstraint]Parameters
multiplierA
CGFloatconstant for the constraint multiplier.Return Value
The layout constraints that were added.
-
A convenience method to remove all the view’s constraints that exist between it and its superview or its superview’s other child views. It does NOT remove constraints between the view and its child views.
Declaration
Swift
public func rsd_removeSiblingAndAncestorConstraints() -
A convenience method to remove all the view’s constraints that exist between it and its superview. It does NOT remove constraints between the view and its child views or constraints on itself (such as width and height).
Declaration
Swift
public func rsd_removeSuperviewConstraints() -
A convenience method to return a constraint on the view that matches the supplied constraint properties. If multiple constraints matching those properties are found, it returns the constraint with the highest priority.
Declaration
Swift
public func rsd_constraint(for attribute: NSLayoutConstraint.Attribute, relation: NSLayoutConstraint.Relation) -> NSLayoutConstraint?Parameters
attributeThe ‘NSLayoutAttribute’ of the constaint to be returned.
relationThe ‘NSLayoutRelation’ of the constraint to be returned.
Return Value
The ‘NSLayoutConstraint’ matching the supplied constraint properties, if any.
-
Get the background color tile for this view. This may be the background color for the view or it may be that this view has a transparent background and gets its real backgrounnd from the super view.
Declaration
Swift
public func backgroundTile() -> RSDColorTile?Return Value
The color tile built for this view or
nilif it could not be determined.
View on GitHub
UIView Extension Reference