Swiftpack.co - Package - luispadron/UICircularProgressRing
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.

UICircularProgressRing

UICircularProgress ring is a library for rendering circular progress rings and timers.

  • Declarative: Written using SwiftUI (legacy UIKit version available), UICircularProgressRing is declarative making it easy to read, and easy to use.
  • Customizable: Designed to be used in production, all of the views are highly customizable without giving up ease of use. This allows the developer to tailor the look, feel and functionality to fit their needs.
  • Tested: Battle tested in many production applications. UICircularProgressRing is also fully unit tested as well as snapshot tested so developers can feel safe.
  • Documented: UICircularProgressRing's public API is 100% documented and its something that is enforced before any code is ever added. This is a resource that will help any new user understand how to get the most out of this library.

iOS 14+ Note

Since Apple has now added a built in ProgressView the need for this library is about to be over. My recommendation: If you can support iOS 14.0 and use the new system ProgressView then you should use that. This library will be continued to be maintained (critical bugs will be fixed, etc) but no new features are planned as we are reaching EOL for this library.

Installation

UICircularProgressRing is available in two major versions. The latest version v7.0+ or legacy versions. The legacy version is written using UIKit and requires a deployment target of iOS 8.0+ or tvOS 10.0+. The latest version is written in SwiftUI and requires iOS 13.0+, macOS 15.0+, tvOS 13.0+ or WatchOS 2.0+.

For legacy installation, follow these instructions.

Swift Package Manager

Simply add this library to your package manifest or follow instructions on adding a package dependency using Xcode here.

.package(
    url: "https://github.com/luispadron/UICircularProgressRing.git",
    .branch("master")
)

Documentation

This projects public API is 100% documented and it's something we spend a lot of time working on. Please make sure to read the documentation before opening any issues, questions, etc.

Read the documentation 📖

Usage

ProgressRing

ProgressRing is a view designed to display some kind of progress, this can be anything which is represented as a percentage in the range [0, ∞). A percentage is represented in decimal format, i.e. 0.5 is 50%. Progress may be a downloading operation, the grade percentage of a users test score, etc. A short example of using ProgressRing is shown below, for more details read the docs or play with the example app.

struct ProgressRingExample: View {
    @State var progress = RingProgress.percent(0.44)

    var body: some View {
        VStack {
            ProgressRing(
                progress: $progress,
                axis: .top,
                clockwise: true,
                outerRingStyle: .init(
                    color: .color(.gray),
                    strokeStyle: .init(lineWidth: 20)
                ),
                innerRingStyle: .init(
                    color: .color(.green),
                    strokeStyle: .init(lineWidth: 10),
                    padding: 5
                )
            )
                .animation(.easeInOut(duration: 5))
                .padding(32)
        }
    }
}

An example image of a ProgressRing view rendered with a green inner circle, a gray outer circle and at 44 percent completion.

TimerRing

TimerRing is a view designed to display time. You initialize the timer by giving it a unit of time and duration, for example: .seconds(60). This means the TimerRing will run for 60 seconds, filling up the inner ring until finally reaching 100% around the entire outer ring. A short example of using TimerRing is shown below, for more details read the docs or play with the example app.

struct TimerRingExample: View {
    @State var isPaused = false
    @State var isDone = false

    var body: some View {
        TimerRing(
            time: .minutes(1),
            delay: .seconds(0.5),
            innerRingStyle: .init(
                color: .color(.green),
                strokeStyle: .init(lineWidth: 16),
                padding: 8
            ),
            isPaused: $isTimerPaused,
            isDone: $isTimerDone
        ) { currentTime in
            Text(timeFormatter.string(from: currentTime))
                .font(.title)
                .bold()
        }
    }
}

A demo image of a timer ring view with a green inner ring, a gray outer ring and at twenty-seven seconds.

Examples

Apps Using UICircularProgressRing

Github

link
Stars: 1524

Releases

Version 7.0.0 - 2020-07-12T22:49:01

Version 7.0.0

  • With this version the library gets a complete rewrite.
  • Written using SwiftUI.
  • Read the README for more info!

Version 6.5.0 - 2020-01-16T05:00:57

Version 6.5.0

  • Fix clipping of value knob

Version 6.4.0 - 2019-10-27T17:59:59

Version 6.4.0

Adds Swift Package Manager support

Version 6.3.0 - 2019-09-15T01:38:09

Version 6.3.0

  • Add new "knob" related features, such as custom knob paths and ability to add images to the progress ring knob. Thanks to @Tom Knapen for the PR!

Version 6.2.1 - 2019-07-15T17:55:46

Version 6.2.1

Fix border width calculation to allow proper fitting of view within given bounds. Thanks to @ zulkis for the PR.

Version 6.2.0 - 2019-05-27T17:50:43

Version 6.2.0

  • Adds ability to start the timer ring from a value other than 0.

Version 6.1.0 - 2019-03-27T14:37:16

Version 6.1.0

  • Migrate to Swift 5.0, thanks to darecki for the PR!

Version 6.0.2 - 2019-03-02T04:50:32

Version 6.0.2

  • Fix issue with formatter initializers being interal, they're now public as intended.

Version 6.0.1 - 2019-02-25T23:56:40

Version 6.0.1

  • Fix bug relating to label being removed during animation (#171)

Version 6.0.0 - 2019-02-22T19:54:47

Version 6.0.0

  • Fixed issue with API of UICircularRingStyle which made it impossible to have both a gradient and outer ring style, etc.
  • Refactor way that UICircularRingValueFormatter works. It's now a simple protocol which anyone can conform to. There are two concrete implementations from 5.0.0 which can still be used, however, they're now structs so cannot be mutated.

Breaking Changes

  • Due to the fact that both the .style property now doesnt allow setting .gradient, this API has been broken. Instead, use the new .gradientOptions property to set a gradient, and .style if you need extra styling on top of gradient
  • Because the value formatter are now structs, they cannot be modified with . syntax. Instead create a brand new formatter and assign to the .valueFormatter property. This will be over all much better in the future, less state and structs are cool!

Version 5.1.0 - 2019-02-08T18:37:58

Version 5.1.0

wow bug fixes already?

  • Fixed issue with timing function for UICircularTimerRing not being set properly
  • Rethink how the timer handler notifies about state, checkout UICircularTimerRing.State

Version 5.0.0 - 2019-02-08T07:08:31

Version 5.0.0

Major changes

  • New UICircularTimerRing view!
  • Complete API overhaul

New changes

  • Refactored the UICircularProgressRing class into two classes, a new base class UICircularRing and the concrete implementation UICircularProgressRing.
  • Added new UICircularTimerRing view which allows setting a timer, pausing, continuing etc. Without worrying about formatting the value string, get accurate time, etc.
  • Almost the entire code and API has been refactored
  • Add new UICircularRingValueFormatter for much nicer handling of formatting values for both views
  • Add new UICircularGradientOptions and updated UICircularRingStyle to be much more "swifty" in order to use case stored properties.
  • Removed a ton of duplicated code between layer and actual ring class, no longer using a ton of @NSManaged properties, instead the layer asks the ring for the needed values. This looks much nicer.

Bug fixes

  • Fixed issue with gradient style not having the correct radius and thus clipping
  • Fixed issues with border clipping in some cases

Breaking changes

  • Removed most Objective-C support, because being forced to write nice, new and maintainable code for both Swift and Objective-C has led to issues with adding new features, and its just not feasible if I want to be able to maintain and do cool things with this project. It sucks in terms of backwards compatibility but in the long run I think it'll be worth it.
  • Removed a ton of @IBInspectable properties, a lot of these like ringStyle behaved really badly, they required using some sort of integer and then converting that into the actual enum type for the ring style, all properties that had this issue have been removed. Until Apple adds support for enum, or more complex properties I'll only be providing IB support for the basic properties of the ring.
  • A lot of API changes were done to the styling of the ring, take a look at the docs, specifically UICircularRingStyle, UICircularGradientOptions, and UICircularRingValueFormatter.

Migrating from version 4

I expect the migration to be painful, I'm very sorry! I felt that the only way to keep this library going into the future was to completely overhaul and update the API and underlying code. This has obviously led to breaking just about everything, again, I'm sorry.

Some tips:

  • If you were using interface builder, take a look at the docs for UICircularRing and UICircularProgressRing. A lot of @IBInspectable properties have been removed/renamed. If these were set in your storyboards/xibs, they will be broken and must be removed from the views settings in IB.
  • Complex styling options are now done in code, with .style, .valueFormatter and optionally .valueKnobStyle. Take a look at the docs to learn more.

Version 4.1.0 - 2018-10-03T22:55:15

Version 4.1.0

  • Fix issues with border drawing and crashes related to it. Thanks to @abdulla-allaith for the PR!

Version 4.0.0 - 2018-09-16T18:20:06

Version 4.0.0

  • Migrate to Swift 4.2, thanks to @chirs-redbeed for initial migration

Version 3.3.2 - 2018-08-24T06:16:25

Version 3.3.2

  • Add check for value being set greater than maxValue Thanks to @byronsalty for the PR!

Version 3.3.1 - 2018-08-22T17:58:48

Version 3.3.1

  • Fixes more issues with pause/continue progress logic. Thanks to @nickdnk for the PR!

Version 3.3.0 - 2018-08-16T22:55:51

Version 3.3.0

  • Fixes issues with inconsistent API. The pauseProgress() and resetProgress() now work as expected/intended. When calling pauseProgress(), the completion on the startProgress function won't be called until it's actually been completed. When calling resetProgress the completion for startProgress is discarded and will no longer be called, since the ring has not actually completed (same with delegate).

    Thanks a lot to @MileyHollenberg for these fixes!

Version 3.2.0 - 2018-07-30T22:29:20

Version 3.2.0

Version 3.1.0 - 2018-07-17T22:48:23

Version 3.1.0

  • Adds three new properties for more fine-grained control of the progress knob. valueKnobShadowBlur, valueKnobShadowOffset, and valueKnobShadowColor. Thanks to @xismic for the contribution!

Version 3.0.0 - 2018-06-27T01:25:48

Version 3.0.0

Tons of new features and improvements!

  • Add new properties showsValueKnob, valueKnobColor, and valueKnobSize as requested by #97
  • Add new continueProgress, pauseProgress, and resetProgress functions which allow fluid continuation and pausing of progress animations.
  • Add new delegate functions didPauseProgress, and didContinueProgress
  • Tons of refactoring and renaming of properties/functionality

Breaking API Changes

Lots please refer to the documentation to get your code up to spec with version 3.0.0

Version 2.2.0 - 2018-06-22T22:59:29

Version 2.2.0

  • Add new isClockwise property which allows users of the library to set whether or not the ring should rotate in a clockwise fashion.

Thanks to @petewalker for adding this!

Version 2.1.3 - 2018-06-22T02:18:44

  • Add example playground

Version 2.1.2 - 2018-06-20T22:22:38

Enable app safe extension API

Version 2.1.1 - 2018-06-11T22:53:39

  • Build with Swift 4.1.2

Version 2.1.0 - 2018-05-14T19:14:08

Version 2.1.0

Add right-to-left language support, thanks eladhayun.

  • New property rightToLeft which when set to true will display the ring with RTL language support, for example when rightToLeft = true, the progress will be GB 100 instead of 100 GB.

Version 2.0.0 - 2018-04-12T23:50:52

Version 2.0.0

Add feature requested in #86 and general clean up and refactoring of API.

  • Add new ring paramater to functions didUpdateProgressValue and willDisplayLabel so that they can be used with multiple rings if needed.

Breaking API Changes

  • finishedUpdatingProgress(forRing:) now changed to finishedUpdatingProgress(for:)
  • didUpdateProgressValue(to:) now changed to didUpdateProgressValue(for:to:)
  • willDisplayLabel(label:) now changed to willDisplayLabel(for:_:)
  • setProgress(value:animationDuration:completion:) now changed to setProgress(to:duration:completion:)

Version 1.8.5 - 2018-04-04T16:37:07

Version 1.8.5

  • Build project with Swift 4.1

Version 1.8.4 - 2018-02-16T19:38:48

Version 1.8.4

  • Mark delegate methods as @objc optional to allow default or optional conformance, thanks to @AbelToy

Version 1.8.3 - 2018-02-14T20:18:05

Version 1.8.3

  • Fix issue with @objc and new willDisplayLabel method in UICircularProgressRingDelegate.

Version 1.8.2 - 2018-02-14T05:07:18

Version 1.8.2

  • Add ability to modify ring label before drawing, thanks to @hohteri