UICircularProgressRingView

@IBDesignable open class UICircularProgressRingView: UIView

UICiruclarProgressRingView

This is the UIView subclass that creates and handles everything to do with the progress ring

This class has a custom CAShapeLayer (UICircularProgressRingLayer) which handels the drawing and animating of the view

The properties in this class correspond with the properties in UICircularProgressRingLayer. When they are set in here, they are also set for the layer and drawn accordingly

Read the docs for what each property does and what can be customized.

Author

Luis Padron

  • The delegate for the UICircularProgressRingView

    Important

    When progress is done updating via UICircularProgressRingView.setValue(:), the finishedUpdatingProgressFor( ring: UICircularProgressRingView) will be called.

    The ring will be passed to the delegate in order to keep track of multiple ring updates if needed.

    Author

    Luis Padron

    Declaration

    Swift

    open weak var delegate: UICircularProgressRingDelegate?
  • Whether or not the progress ring should be a full circle.

    What this means is that the outer ring will always go from 0 - 360 degrees and the inner ring will be calculated accordingly depending on current value.

    Important

    Default = true

    When this property is true any value set for endAngle will be ignored.

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var fullCircle: Bool = true
  • The value property for the progress ring.

    Important

    Default = 0

    Must be a non-negative value. If this value falls below minValue it will be clamped and set equal to minValue.

    This cannot be used to get the value while the ring is animating, to get current value while animating use currentValue.

    The current value of the progress ring after animating, use setProgress(value:) to alter the value with the option to animate and have a completion handler.

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var value: CGFloat = 0
  • The current value of the progress ring

    This will return the current value of the progress ring, if the ring is animating it will be updated in real time. If the ring is not currently animating then the value returned will be the value property of the ring

    Author

    Luis Padron

    Declaration

    Swift

    open var currentValue: CGFloat?
  • The minimum value for the progress ring. ex: (0) -> 100.

    Important

    Default = 100

    Must be a non-negative value, the absolute value is taken when setting this property.

    The value of the progress ring must NOT fall below minValue if it does the value property is clamped and will be set equal to value, you will receive a warning message in the console.

    Making this value greater than

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var minValue: CGFloat = 0.0
  • The maximum value for the progress ring. ex: 0 -> (100)

    Important

    Default = 100

    Must be a non-negative value, the absolute value is taken when setting this property.

    Unlike the minValue member value can extend beyond maxValue. What happens in this case is the inner ring will do an extra loop through the outer ring, this is not noticible however.

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var maxValue: CGFloat = 100.0
  • The style of the progress ring.

    Type: UICircularProgressRingStyle

    The five styles include inside, ontop, dashed, dotted, and gradient

    Important

    Default = UICircularProgressRingStyle.inside

    Author

    Luis Padron

    Declaration

    Swift

    open var ringStyle: UICircularProgressRingStyle = .inside
  • An array of CGFloats, used to calculate the dash length for viewStyle = 3

    Important

    Default = [7.0, 7.0]

    Author

    Luis Padron

    Declaration

    Swift

    open var patternForDashes: [CGFloat] = [7.0, 7.0]
  • The start angle for the entire progress ring view.

    Please note that Cocoa Touch uses a clockwise rotating unit circle. I.e: 90 degrees is at the bottom and 270 degrees is at the top

    Important

    Default = 0 (degrees)

    Values should be in degrees (they’re converted to radians internally)

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var startAngle: CGFloat = 0
  • The end angle for the entire progress ring

    Please note that Cocoa Touch uses a clockwise rotating unit circle. I.e: 90 degrees is at the bottom and 270 degrees is at the top

    Important

    Default = 360 (degrees)

    Values should be in degrees (they’re converted to radians internally)

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var endAngle: CGFloat = 360
  • The colors which will be used to create the gradient.

    Only used when ringStyle is .gradient

    The colors should be in the order they will be drawn in.

    Important

    By default this property will be an empty array.

    If this array is empty, no gradient will be drawn.

    Author

    Luis Padron

    Declaration

    Swift

    open var gradientColors: [UIColor] = [UIColor]()
  • The location for each color provided in gradientColors; each location must be a CGFloat value in the range of 0 to 1, inclusive. If 0 and 1 are not in the locations array, Quartz uses the colors provided that are closest to 0 and 1 for those locations.

    If locations is nil, the first color in gradientColors is assigned to location 0, the last color in gradientColors is assigned to location 1, and intervening colors are assigned locations that are at equal intervals in between.

    The locations array should contain the same number of items as the gradientColors array.

    Important

    By default this property will be nil

    Author

    Luis Padron

    Declaration

    Swift

    open var gradientColorLocations: [CGFloat]? = nil
  • The start location for the gradient. This property determines where the gradient will begin to draw, for all possible values see UICircularProgressRingGradientPosition.

    Important

    By default this property is .topRight

    Author

    Luis Padron

    Declaration

    Swift

    open var gradientStartPosition: UICircularProgressRingGradientPosition = .topRight
  • The end location for the gradient. This property determines where the gradient will end drawing, for all possible values see UICircularProgressRingGradientPosition.

    Important

    By default this property is .bottomLeft

    Author

    Luis Padron

    Declaration

    Swift

    open var gradientEndPosition: UICircularProgressRingGradientPosition = .bottomLeft
  • The width of the outer ring for the progres bar

    Important

    Default = 10.0

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var outerRingWidth: CGFloat = 10.0
  • The color for the outer ring

    Important

    Default = UIColor.gray

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var outerRingColor: UIColor = UIColor.gray
  • The style for the tip/cap of the outer ring

    Type: CGLineCap

    Important

    Default = CGLineCap.butt

    This is only noticible when ring is not a full circle.

    Author

    Luis Padron

    Declaration

    Swift

    open var outerCapStyle: CGLineCap = .butt
  • The width of the inner ring for the progres bar

    Important

    Default = 5.0

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var innerRingWidth: CGFloat = 5.0
  • The color of the inner ring for the progres bar

    Important

    Default = UIColor.blue

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var innerRingColor: UIColor = UIColor.blue
  • The spacing between the outer ring and inner ring

    Important

    This only applies when using progressRingStyle = 1

    Default = 1

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var innerRingSpacing: CGFloat = 1
  • The style for the tip/cap of the inner ring

    Type: CGLineCap

    Important

    Default = CGLineCap.round

    Author

    Luis Padron

    Declaration

    Swift

    open var innerCapStyle: CGLineCap = .round
  • A toggle for showing or hiding the value label. If false the current value will not be shown.

    Important

    Default = true

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var shouldShowValueText: Bool = true
  • The text color for the value label field

    Important

    Default = UIColor.black

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var fontColor: UIColor = UIColor.black
  • The font to be used for the progress indicator. All font attributes are specified here except for font color, which is done using fontColor.

    Important

    Default = UIFont.systemFont(ofSize: 18)

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var font: UIFont = UIFont.systemFont(ofSize: 18)
  • The name of the value indicator the value label will appened to the value Example: GB -> 100 GB

    Important

    Default = %

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var valueIndicator: String = "%"
  • A toggle for showing or hiding floating points from the value in the value label

    Important

    Default = false (dont show)

    To customize number of decmial places to show, assign a value to decimalPlaces.

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var showFloatingPoint: Bool = false
  • The amount of decimal places to show in the value label

    Important

    Default = 2

    Only used when showFloatingPoint = true

    Author

    Luis Padron

    Declaration

    Swift

    @IBInspectable open var decimalPlaces: Int = 2
  • The type of animation function the ring view will use

    Important

    Default = kCAMediaTimingFunctionEaseIn

    String should be from kCAMediaTimingFunction_____

    Only used when calling .setValue(animated: true)

    Author

    Luis Padron

    Declaration

    Swift

    open var animationStyle: String = kCAMediaTimingFunctionEaseIn
  • This returns whether or not the ring is currently animating

    Important

    Get only property

    Author

    Luis Padron

    Declaration

    Swift

    open var isAnimating: Bool
  • Overrides the default layer with the custom UICircularProgressRingLayer class

    Declaration

    Swift

    override open class var layerClass: AnyClass
  • Overriden public init to initialize the layer and view

    Declaration

    Swift

    override public init(frame: CGRect)
  • Overriden public init to initialize the layer and view

    Declaration

    Swift

    required public init?(coder aDecoder: NSCoder)
  • Overriden because of custom layer drawing in UICircularProgressRingLayer

    Declaration

    Swift

    open override func draw(_ rect: CGRect)
  • Typealias for the setProgress(:) method closure

    Declaration

    Swift

    public typealias ProgressCompletion = (() -> Void)
  • Sets the current value for the progress ring, calling this method while ring is animating will cancel the previously set animation and start a new one.

    Important

    Animatin duration = 0 will cause no animation to occur, and value will instantly be set

    Author

    Luis Padron

    Declaration

    Swift

    open func setProgress(value: CGFloat, animationDuration: TimeInterval,
                          completion: ProgressCompletion? = nil)

    Parameters

    newVal

    The value to be set for the progress ring

    animationDuration

    The time interval duration for the animation

    completion

    The completion closure block that will be called when animtion is finished (also called when animationDuration = 0), default is nil