UIView

public extension UIView
  • Positions where a view may be placed, relative to a superview.

    See more

    Declaration

    Swift

    enum Position
  • Creates a SimpleAnimation that allows you to add different actions and transformations to the view, executing each of them only when the previous one is finished in the order they were added.

    Declaration

    Swift

    func simpleAnimation() -> SimpleAnimation

    Return Value

    SimpleAnimation for this view

  • Creates a MixedAnimation that allows you to add different actions and transformations to the view, concatenating and executing first all transformations and when that is done, executes each action that was added.

    Declaration

    Swift

    func mixedAnimation(withDuration duration: TimeInterval) -> MixedAnimation

    Return Value

    MixedAnimation for this view

  • Creates a ChainedAnimation that allows you to combine SimpleAnimations and MixedAnimations, and execute them in the order they were added.

    Declaration

    Swift

    func chainedAnimation(loop: Bool = false) -> ChainedAnimation

    Return Value

    ChainedAnimation for this view

  • Adds a shake animation that executes the closure when long pressed

    Declaration

    Swift

    func shake(withDuration duration: TimeInterval = 0.05, repeatShake: Float = 3)

    Parameters

    duration

    Time in seconds the animation will be executed. Default is 0.05

    repeatShake

    Number of times the view will change position. Default is 3

  • Allows dragging the view and executing actions when the press gesture begins or ends.

    Declaration

    Swift

    func isDraggable(returnToPosition: Bool = true, withDuration duration: TimeInterval = 0.5, onDragStarted: ((UIView) -> Void)?, onDragFinished: ((UIView) -> Void)?)

    Parameters

    returnToPosition

    Whether the view will return to its original position when released. Default is true

    duration

    Time in seconds that it takes for the view to return to the original position. Default is 0.5

    onDragStarted

    The closure that will execute when the view is held

    onDragFinished

    The closure that will execute when the view is released

  • Loads the view into the specified containerView.

    Note

    If you decide to use constraints to determine the size, the container’s frame doesn’t need to be final. Because of this, it can be used in loadView(), viewDidLoad() or viewWillAppear(animated:). We strongly recommend to work with constraints as a better practice than frames. Also, this function matches left inset to leading and right to trailing of the view.

    Declaration

    Swift

    func add(into containerView: UIView,
             with insets: UIEdgeInsets = .zero,
             in viewPositioning: ViewPositioning = .front,
             layout: LayoutMode = .constraints,
             respectSafeArea: Bool = false)

    Parameters

    containerView

    The container view.

    insets

    Insets that separate self from the container view. By default, .zero.

    viewPositioning

    Back or Front. By default, .front.

    layout

    Enum indicating the layout mode. By default, .constraints.

  • Adds a border to the top of the view, inside the view’s bounds.

    Note

    If you decide to use constraints to determine the size, self’s frame doesn’t need to be final. Because of this, it can be used in loadView(), viewDidLoad() or viewWillAppear(animated:). We strongly recommend to work with constraints as a better practice than frames.

    Declaration

    Swift

    @discardableResult
    func add(top border: BorderViewProperties,
             withLeftOffset left: CGFloat = 0,
             rightOffset right: CGFloat = 0,
             layout: LayoutMode = .constraints) -> BorderView

    Parameters

    border

    Models characteristics of the border to be added.

    leftOffset

    Offset from the view’s left border to where the border should start. By default, 0.

    rightOffset

    Offset from the view’s right border to where the border should start. By default, 0.

    layout

    Enum indicating the layout mode. By default, .constraints.

  • Adds a border to the bottom of the view, inside the view’s bounds.

    Note

    If you decide to use constraints to determine the size, self’s frame doesn’t need to be final. Because of this, it can be used in loadView(), viewDidLoad() or viewWillAppear(animated:). We strongly recommend to work with constraints as a better practice than frames.

    Declaration

    Swift

    @discardableResult
    func add(bottom border: BorderViewProperties,
             withLeftOffset left: CGFloat = 0, rightOffset right: CGFloat = 0,
             layout: LayoutMode = .constraints) -> BorderView

    Parameters

    border

    Models characteristics of the border to be added.

    leftOffset

    Offset from the view’s left border to where the border should start. By default, 0.

    rightOffset

    Offset from the view’s right border to where the border should start. By default, 0.

    layout

    Enum indicating the layout mode. By default, .constraints.

  • Adds a border to the left of the view, inside the view’s bounds.

    Note

    If you decide to use constraints to determine the size, self’s frame doesn’t need to be final. Because of this, it can be used in loadView(), viewDidLoad() or viewWillAppear(animated:). We strongly recommend to work with constraints as a better practice than frames.

    Declaration

    Swift

    @discardableResult
    func add(left border: BorderViewProperties,
             withTopOffset top: CGFloat = 0,
             bottomOffset bottom: CGFloat = 0,
             layout: LayoutMode = .constraints) -> BorderView

    Parameters

    border

    Models characteristics of the border to be added.

    leftOffset

    Offset from the view’s left border to where the border should start. By default, 0.

    rightOffset

    Offset from the view’s right border to where the border should start. By default, 0.

    layout

    Enum indicating the layout mode. By default, .constraints.

  • Adds a border to the right of the view, inside the view’s bounds.

    Note

    If you decide to use constraints to determine the size, self’s frame doesn’t need to be final. Because of this, it can be used in loadView(), viewDidLoad() or viewWillAppear(animated:). We strongly recommend to work with constraints as a better practice than frames.

    Declaration

    Swift

    @discardableResult
    func add(right border: BorderViewProperties,
             withTopOffset top: CGFloat = 0,
             bottomOffset bottom: CGFloat = 0,
             layout: LayoutMode = .constraints) -> BorderView

    Parameters

    border

    Models characteristics of the border to be added.

    leftOffset

    Offset from the view’s left border to where the border should start. By default, 0.

    rightOffset

    Offset from the view’s right border to where the border should start. By default, 0.

    layout

    Enum indicating the layout mode. By default, .constraints.

  • Removes the border view from self, only if the border was a child view to self.

    Declaration

    Swift

    func remove(border: BorderView)
  • Adds borders to the selected sides of the view, inside the view’s bounds.

    Note

    If you decide to use constraints to determine the size, self’s frame doesn’t need to be final. Because of this, it can be used in loadView(), viewDidLoad() or viewWillAppear(animated:). We strongly recommend to work with constraints as a better practice than frames.

    Declaration

    Swift

    func addBorders(properties: BorderViewProperties, positions: [BorderPosition], layout: LayoutMode = .constraints)

    Parameters

    properties

    characteristics of the borders to be added.

    positions

    the sides of the view where borders will be added.

    layout

    Enum indicating the layout mode. By default, .constraints.

  • Adds a drop shadow to the selected view.

    Note

    If you decide to use constraints to determine the size, self’s frame doesn’t need to be final. Because of this, it can be used in loadView(), viewDidLoad() or viewWillAppear(animated:). We strongly recommend to work with constraints as a better practice than frames.

    Declaration

    Swift

    func addShadow(color: CGColor = UIColor.black.cgColor,
                   size: CGSize = CGSize(width: 0, height: 2),
                   radius: CGFloat = 2.5,
                   opacity: Float = 0.2,
                   cornerRadius: CGFloat = 5)

    Parameters

    color

    the color of the shadow.

    size

    horizontal and vertical size of the shadow.

    radius

    the overall extension of the shadow from the center of the view.

    cornerRadius

    how rounded the corners of the shadow are.

  • Adds a long-press gesture recognizer that executes the closure when long pressed

    Declaration

    Swift

    func addLongPressGestureRecognizer(numberOfTapsRequired: Int = 0,
                                       numberOfTouchesRequired: Int = 1,
                                       minimumPressDuration: TimeInterval = 0.5,
                                       allowableMovement: CGFloat = 10,
                                       action: ((UILongPressGestureRecognizer) -> Void)?)

    Parameters

    numberOfTapsRequired

    The number of full taps required before the press for gesture to be recognized. Default is 0

    numberOfTouchesRequired

    Number of fingers that must be held down for the gesture to be recognized. Default is 1

    minimumPressDuration

    Time in seconds the fingers must be held down for the gesture to be recognized. Default is 0.5

    allowableMovement

    Maximum movement in pixels allowed before the gesture fails. Once recognized (after minimumPressDuration) there is no limit on finger movement for the remainder of the touch tracking. Default is 10

    action

    The closure that will execute when the view is long pressed

  • Adds a pan gesture recognizer that executes the closure when panned

    Declaration

    Swift

    func addPanGestureRecognizer(minimumNumberOfTouches: Int = 1,
                                 maximumNumberOfTouches: Int = .max,
                                 action: ((UIPanGestureRecognizer) -> Void)?)

    Parameters

    minimumNumberOfTouches

    The minimum number of touches required to match. Default is 1

    maximumNumberOfTouches

    The maximum number of touches that can be down. Default is Int.max

    action

    The closure that will execute when the view is panned

  • Adds a pinch gesture recognizer that executes the closure when pinched

    Declaration

    Swift

    func addPinchGestureRecognizer(action: ((UIPinchGestureRecognizer) -> Void)?)

    Parameters

    action

    The closure that will execute when the view is pinched

  • Adds a rotation gesture recognizer that executes the closure when rotated

    Declaration

    Swift

    func addRotationGestureRecognizer(action: ((UIRotationGestureRecognizer) -> Void)?)

    Parameters

    action

    The closure that will execute when the view is rotated

  • Adds a screen-edge-pan gesture recognizer that executes the closure when panned on the edge

    Declaration

    Swift

    func addScreenEdgePanGestureRecognizer(edge: UIRectEdge, action: ((UIScreenEdgePanGestureRecognizer) -> Void)?)

    Parameters

    edge

    The edge on which this gesture recognizes, relative to the current interface orientation.

    action

    The closure that will execute when the edge of the view is panned

  • Adds a swipe gesture recognizer that executes the closure when swiped

    Declaration

    Swift

    func addSwipeGestureRecognizer(numberOfTouchesRequired: Int = 1,
                                   direction: UISwipeGestureRecognizer.Direction = .right,
                                   action: ((UISwipeGestureRecognizer) -> Void)?)

    Parameters

    numberOfTouchesRequired

    The number of fingers that must swipe. Default is 1

    direction

    The desired direction of the swipe. Multiple directions may be specified if they will result in the same behavior (for example, UITableView swipe delete). Default is right

    action

    The closure that will execute when the view is swiped

  • Adds a tap gesture recognizer that executes the closure when tapped

    Declaration

    Swift

    func addTapGestureRecognizer(numberOfTapsRequired: Int = 1,
                                 numberOfTouchesRequired: Int = 1,
                                 action: ((UITapGestureRecognizer) -> Void)?)

    Parameters

    numberOfTapsRequired

    The number of taps required to match. Default is 1

    numberOfTouchesRequired

    The number of fingers required to match. Default is 1

    action

    The number of fingers required to match. Default is 1

  • ViewGradient applied currently to the view. A view can only have one gradient at a time. When setting this property to a new gradient, the old one will be removed, and when set to .none the current one will be removed. The gradient will always have the same direction in relation to the view’s orientation at a certain time. The gradient will always acommodate to the view’s change in size or orientation.

    Warning

    To avoid memory leak and crashes, you should set the gradient to .none before deallocating the view.

    Declaration

    Swift

    var gradient: ViewGradient? { get set }
  • This is an extension for layout compatibility between iOS 11 and lower versions. If the native safe layout guide is not available, then return a regular layout guide.

    Declaration

    Swift

    var safeLayoutGuide: UILayoutGuide { get }
  • Indicates wether this functionality is available (iOS 11.0 or newer).

    Declaration

    Swift

    var safeLayoutInsets: UIEdgeInsets { get }