UIView
public extension UIView
-
Change layer’s background color
Declaration
Swift
@discardableResult func layer(backgroundColor color: CGColor?) -> SelfParameters
colorYou can use
UIColor.colorName.cgColorto 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) -> SelfParameters
gravityWill be used as layer’s gravity.
-
Change layer’s corner radius.
Declaration
Swift
@discardableResult func layer(cornerRadius: Float) -> SelfParameters
radiusvalue, defines corner radius.
-
Change layer’s border color.
Declaration
Swift
@discardableResult func layer(borderColor: CGColor?) -> SelfParameters
coloruse
UIColor.colorName.cgColorto 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) -> SelfParameters
widthWill be used as width value.
-
Change layer’s opacity
Declaration
Swift
@discardableResult func layer(opacity: Float) -> SelfParameters
valueWill 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?) -> SelfParameters
layerAllows to set existing type or create new one inside closure.
-
Set
isDoubleSidedparameter.Declaration
Swift
@discardableResult func layer(isDoubleSided: Bool) -> Self -
Set masked corners value.
Declaration
Swift
@available(iOS 11.0, *) @discardableResult func layer(maskedCorners: @autoclosure () -> CACornerMask) -> SelfParameters
cornersYou can pass exisiting value or create it inside closure
-
Set layer’s shadow opacity.
Declaration
Swift
@discardableResult func layer(shadowOpacity: Float) -> SelfParameters
opacity -
Change layer’s shadow color.
Declaration
Swift
@discardableResult func layer(shadowColor: CGColor?) -> SelfParameters
colorPass
UIColor.colorName.cgColorto pass UIColor value -
Change layer’s shadow color.
Declaration
Swift
@discardableResult func layer(shadowColor: UIColor?) -> Self -
Set layer’s shadow radius. Takes
Floatand converts it toCGFloatfor programmer’s convenienceDeclaration
Swift
@discardableResult func layer(shadowRadius: Float) -> SelfParameters
radius -
Changes layer’s shadowOffset to given in parameter
Declaration
Swift
@discardableResult func layer(shadowOffset: @autoclosure () -> CGSize) -> SelfParameters
offsetoffset 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?) -> SelfParameters
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]?) -> SelfParameters
styleYou can pass exisiting value or create new one inside closure.
-
Set layer’s filters.
Declaration
Swift
@discardableResult func layer(filters: @autoclosure () -> [Any]?) -> SelfParameters
filtersYou can pass exisiting value or create new one inside closure.
-
Set layer’s
isOpaqueBoolean.Declaration
Swift
@discardableResult func layer(isOpaque: Bool) -> Self -
Set layer’s
drawsAsynchronouslyDeclaration
Swift
@discardableResult func layer(drawsAsynchronously: Bool) -> Self -
Add animation to a layer.
Declaration
Swift
@discardableResult func layer(addAnimation animation: CAAnimation, forKey key: String?) -> SelfParameters
keyKey which allows to identify given animation.
animationYou 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) -> SelfParameters
keyKey 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) -> SelfParameters
closureA 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 ) -> UIViewParameters
linkA Chain of events that must be completed for the view to be shown
updateA closure to handle updating the view when the chain is completed
centeredLoadingViewA 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 ) -> UIViewParameters
linkA Chain of events that must be completed for the view to be shown
updateA closure to handle updating the view when the chain is completed
embeddedLoadingViewA 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 ) -> UIViewParameters
linkA Chain of events that must be completed for the view to be shown
updateA closure to handle updating the view when the chain is completed
centeredLoadingViewA 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 ) -> UIViewParameters
linkA Chain of events that must be completed for the view to be shown
updateA closure to handle updating the view when the chain is completed
embeddedLoadingViewA 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
withPaddingThe padding surrounding the embedded view (Default: 0)
backgroundColorThe color to set as the backgroundColor of the parent view (Default: .clear)
closureA 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
withPaddingThe
Paddingsurrounding the embedded viewbackgroundColorThe color to set as the backgroundColor of the parent view (Default: .clear)
closureA 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?] ) -> SelfParameters
withSpacingThe amount of spacing between each child view (Default: 0)
paddingThe amount of space between this view and its parent view (Default: 0)
alignmentThe layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment) (Default: .fill)
distributionThe layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution) (Default: .fill)
axisKeys that specify a horizontal or vertical layout constraint between objects (source: NSLayoutConstraint.Axis)
closureA 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?] ) -> SelfParameters
withSpacingThe amount of spacing between each child view (Default: 0)
paddingThe amount of space between this view and its parent view
alignmentThe layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment) (Default: .fill)
distributionThe layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution) (Default: .fill)
axisKeys that specify a horizontal or vertical layout constraint between objects (source: NSLayoutConstraint.Axis)
closureA 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?] ) -> SelfParameters
withSpacingThe amount of spacing between each child view (Default: 0)
paddingThe amount of space between this view and its parent view (Default: 0)
alignmentThe layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment) (Default: .fill)
distributionThe layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution) (Default: .fill)
closureA 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?] ) -> SelfParameters
withSpacingThe amount of spacing between each child view (Default: 0)
paddingThe amount of space between this view and its parent view
alignmentThe layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment) (Default: .fill)
distributionThe layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution) (Default: .fill)
closureA 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?] ) -> SelfParameters
withSpacingThe amount of spacing between each child view (Default: 0)
paddingThe amount of space between this view and its parent view (Default: 0)
alignmentThe layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment) (Default: .fill)
distributionThe layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution) (Default: .fill)
closureA 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?] ) -> SelfParameters
withSpacingThe amount of spacing between each child view (Default: 0)
paddingThe amount of space between this view and its parent view
alignmentThe layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment) (Default: .fill)
distributionThe layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution) (Default: .fill)
closureA 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 ) -> SelfParameters
withPaddingThe amount of space between the embedded view and this view (Default: 0)
closureA trailing closure that accepts a view
-
Center a View
Declaration
Swift
@discardableResult func center(_ closure: () -> UIView) -> SelfParameters
closureA 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 ) -> SelfParameters
withPaddingThe amount of space between the embedded view and this view
closureA 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) -> UIViewParameters
paddingThe 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) -> SelfParameters
heightValue for the heightAnchor (Default: nil)
widthValue 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 ) -> SelfParameters
heightValue for the heightAnchor (Default: nil)
widthValue 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]) -> SelfParameters
constraintsA 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) -> SelfParameters
xValue to add to the center.x (Default: nil)
yValue 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) -> SelfParameters
xValue to set the center.x (Default: nil)
yValue 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 ) -> SelfParameters
withDurationDuration of the animation
animationClosure which changes to the view are animated
completionClosure 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 ) -> SelfParameters
withDurationDuration of the animation
delayThe duration which the animation should be delayed
otionsThe UIView.AnimationOptions for the animation
animationClosure which changes to the view are animated
completionClosure which runs once the animation has been completed (Default: nil)
-
Hide the view
Declaration
Swift
@discardableResult func hide(if shouldHide: Bool) -> SelfParameters
ifA bool that determines if the view should be hidden
-
Hide the view
Declaration
Swift
@discardableResult func hide(if shouldHide: () -> Bool) -> SelfParameters
ifA 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) -> SelfParameters
closureA 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) -> SelfParameters
titleThe title of the currentViewController
-
Set the left barButton
Declaration
Swift
@discardableResult func navigateSetLeft(barButton: UIBarButtonItem?, animated: Bool = true) -> SelfParameters
barButtonThe UIBarButtonItem to be set
animatedShould animate setting the left UIBarButtonItem (Default: true)
-
Set the right barButton
Declaration
Swift
@discardableResult func navigateSetRight(barButton: UIBarButtonItem?, animated: Bool = true) -> SelfParameters
barButtonThe UIBarButtonItem to be set
animatedShould animate setting the right UIBarButtonItem (Default: true)
-
Set the left barButtons
Declaration
Swift
@discardableResult func navigateSetLeft(barButtons: [UIBarButtonItem]?, animated: Bool = true) -> SelfParameters
barButtonThe [UIBarButtonItem] to be set
animatedShould animate setting the left UIBarButtonItem
-
Set the right barButtons
Declaration
Swift
@discardableResult func navigateSetRight(barButtons: [UIBarButtonItem]?, animated: Bool = true) -> SelfParameters
barButtonThe [UIBarButtonItem] to be set
animatedShould 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
View on GitHub
UIView Extension Reference