UIView

class UIView : UIResponder, NSCoding, UIAppearance, UIAppearanceContainer, UIDynamicItem, UITraitEnvironment, UICoordinateSpace, UIFocusItem, UIFocusItemContainer, CALayerDelegate

This extesion adds some useful functions to UIView.

  • Direction of flip animation.

    • top: Flip animation from top.
    • left: Flip animation from left.
    • right: Flip animation from right.
    • bottom: Flip animation from bottom.
    See more

    Declaration

    Swift

    public enum UIViewAnimationFlipDirection : String
  • Direction of the translation.

    • leftToRight: Translation from left to right.
    • rightToLeft: Translation from right to left.
    See more

    Declaration

    Swift

    public enum UIViewAnimationTranslationDirection : Int
  • Direction of the linear gradient.

    • vertical: Linear gradient vertical.
    • horizontal: Linear gradient horizontal.
    • diagonalLeftToRightAndTopToDown: Linear gradient from left top to right down.
    • diagonalLeftToRightAndDownToTop: Linear gradient from left down to right top.
    • diagonalRightToLeftAndTopToDown: Linear gradient from right top to left down.
    • diagonalRightToLeftAndDownToTop: Linear gradient from right down to left top.
    See more

    Declaration

    Swift

    public enum UIViewGradientDirection
  • Type of gradient.

    • linear: Linear gradient.
    • radial: Radial gradient.
    See more

    Declaration

    Swift

    public enum UIViewGradientType
  • Create an UIView with the given frame and background color.

    Declaration

    Swift

    public convenience init(frame: CGRect, backgroundColor: UIColor)

    Parameters

    frame

    UIView frame.

    backgroundColor

    UIView background color.

  • Creates a border around the UIView.

    Declaration

    Swift

    public func border(color: UIColor, radius: CGFloat, width: CGFloat)

    Parameters

    color

    Border color.

    radius

    Border radius.

    width

    Border width.

  • Removes border around the UIView.

    Declaration

    Swift

    public func removeBorder(maskToBounds: Bool = true)
  • Set the corner radius of UIView only at the given corner. Currently doesn’t support frame property changes. If you change the frame, you have to call this function again.

    Declaration

    Swift

    public func cornerRadius(corners: UIRectCorner, radius: CGFloat)

    Parameters

    corners

    Corners to apply radius.

    radius

    Radius value.

  • Set the corner radius of UIView for all corners. This function supports frame property changes, it’s different from cornerRadius(corners: UIRectCorner, radius: CGFloat) that doesn’t support it.

    Declaration

    Swift

    public func cornerRadius(_ radius: CGFloat)

    Parameters

    radius

    Radius value.

  • Create a shadow on the UIView.

    Declaration

    Swift

    public func shadow(offset: CGSize, opacity: Float, radius: CGFloat, cornerRadius: CGFloat = 0, color: UIColor = UIColor.black)

    Parameters

    offset

    Shadow offset.

    opacity

    Shadow opacity.

    radius

    Shadow radius.

    color

    Shadow color. Default is black.

  • Removes shadow around the UIView.

    Declaration

    Swift

    public func removeShadow(maskToBounds: Bool = true)
  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func gradient(colors: [UIColor], direction: UIViewGradientDirection) -> CAGradientLayer
  • Create a smooth linear gradient, requires more computational time than

    gradient(colors:,direction:)
    

    Declaration

    Swift

    public func smoothGradient(colors: [UIColor], direction: UIViewGradientDirection, type: UIViewGradientType = .linear)

    Parameters

    colors

    Array of UIColor instances.

    direction

    Direction of the gradient.

  • Adds a motion effect to the view.

    Declaration

    Swift

    public func applyMotionEffects()
  • Take a screenshot of the current view

    Declaration

    Swift

    public func screenshot(save: Bool = false) -> UIImage?

    Parameters

    save

    Save the screenshot in user pictures. Default is false.

    Return Value

    Returns screenshot as UIImage

  • Removes all subviews from current view

    Declaration

    Swift

    public func removeAllSubviews()
  • Create a shake effect.

    Declaration

    Swift

    public func shake(count: Float = 2, duration: TimeInterval = 0.15, translation: Float = 5)

    Parameters

    count

    Shakes count. Default is 2.

    duration

    Shake duration. Default is 0.15.

    translation

    Shake translation. Default is 5.

  • Create a pulse effect.

    Declaration

    Swift

    public func pulse(count: Float = 1, duration: TimeInterval = 1)

    Parameters

    count

    Pulse count. Default is 1.

    duration

    Pulse duration. Default is 1.

  • Create a heartbeat effect.

    Declaration

    Swift

    public func heartbeat(count: Float = 1, maxSize: CGFloat = 1.4, durationPerBeat: TimeInterval = 0.5)

    Parameters

    count

    Seconds of animation. Default is 1.

    maxSize

    Maximum size of the object to animate. Default is 1.4.

    durationPerBeat

    Duration per beat. Default is 0.5.

  • Create a flip effect.

    Declaration

    Swift

    public func flip(duration: TimeInterval, direction: UIViewAnimationFlipDirection)

    Parameters

    duration

    Seconds of animation.

    direction

    Direction of the flip animation.

  • Translate the UIView around the topView.

    Declaration

    Swift

    public func translateAround(topView: UIView, duration: CGFloat, direction: UIViewAnimationTranslationDirection, repeatAnimation: Bool = true, startFromEdge: Bool = true)

    Parameters

    topView

    Top view to translate to.

    duration

    Duration of the translation.

    direction

    Direction of the translation.

    repeatAnimation

    If the animation must be repeat or no.

    startFromEdge

    If the animation must start from the edge.

  • Animate along path.

    Declaration

    Swift

    public func animate(path: UIBezierPath, count: Float = 1, duration: TimeInterval, autoreverses: Bool = false)

    Parameters

    path

    Path to follow.

    count

    Animation repeat count. Default is 1.

    duration

    Animation duration.

  • Inspectable border size.

    Declaration

    Swift

    @IBInspectable
    public var borderWidth: CGFloat { get set }
  • Inspectable border color.

    Declaration

    Swift

    @IBInspectable
    public var borderColor: UIColor { get set }
  • Inspectable mask to bounds.

    Set it to true if you want to enable corner radius.

    Set it to false if you want to enable shadow.

    Declaration

    Swift

    @IBInspectable
    public var maskToBounds: Bool { get set }
  • Inspectable corners size.

    Remeber to set maskToBounds to true.

    Declaration

    Swift

    @IBInspectable
    public var cornerRadius: CGFloat { get set }
  • Inspectable shadow color.

    Remeber to set maskToBounds to false.

    Declaration

    Swift

    @IBInspectable
    public var shadowColor: UIColor { get set }
  • Inspectable shadow opacity.

    Remeber to set maskToBounds to false.

    Declaration

    Swift

    @IBInspectable
    public var shadowOpacity: Float { get set }
  • Inspectable shadow offset X.

    Remeber to set maskToBounds to false.

    Declaration

    Swift

    @IBInspectable
    public var shadowOffsetX: CGFloat { get set }
  • Inspectable shadow offset Y.

    Remeber to set maskToBounds to false.

    Declaration

    Swift

    @IBInspectable
    public var shadowOffsetY: CGFloat { get set }
  • Inspectable shadow radius.

    Remeber to set maskToBounds to false.

    Declaration

    Swift

    @IBInspectable
    public var shadowRadius: CGFloat { get set }