Home

Awesome

CircularProgress

SwiftUI package that creates an animated circular progress bar

Installation: It requires at least iOS 15, iPadOS 15, macOS 12 and Xcode 13!

In Xcode go to File -> Add Packages... and paste in the repo's url: https://github.com/ArnavMotwani/CircularProgressSwiftUI.git then either select a version or the main branch

I will update the main branch more frequently with minor changes, while the version will only increase with significant changes.

There also a branch called iOS13 which supports iOS 13+ and macOS 10_15+

Usage:

Import the package into the file with import CircularProgress

Example:

Here is how the default view, with no customizations, can be implemented

<p float="center"> <img src="./Gifs/example.gif" width="200" /> </p>
import SwiftUI
import CircularProgress

struct ContentView: View {
    @State var count = 0
    let total = 10
    var progress: CGFloat{
        return CGFloat(count)/CGFloat(total)
    }
    var body: some View {
        VStack {
            CircularProgressView(count: count, total: total, progress: progress)
                .padding(50)
            HStack{
                Button("Decrease", action: {self.count -= 1})
                Spacer()
                Button("Increase", action: {self.count += 1})
            }
            .padding(50)
        }
    }
}

Fill Customization:

The Progress Bar can be filled with a Linear or an Angular Gradient. By default the fill is LinearGradient(gradient: Gradient(colors: [Color.green, Color.blue]), startPoint: .top, endPoint: .bottom) however you can pass a custom Linear or Angular Gradient to the fill Parameter.

Parameters:

parameteroptional?typedescriptiondefault
countrequiredIntCurrent value (larger text in the centre)-
totalrequiredIntTotal value (smaller text in the centre)-
progressrequiredCGFloatProgress of the bar-
fontOneoptionalFontFont of larger text in the centreFont.system(size: 75, weight: .bold, design: .rounded)
fontTwooptionalFontFont of smaller text in the centreFont.system(size: 25, weight: .bold, design: .rounded)
colorOneoptionalColorColor of larger text in the centreColor.primary
colorTwooptionalColorColor of smaller text in the centreColor.gray
filloptionalLinearGradient or AngularGradientFill of the progress barLinearGradient(gradient: Gradient(colors: [Color.green, Color.blue]), startPoint: .top, endPoint: .bottom)
lineWidthoptionalCGFloatWidth of the progress bar25.0
lineCapoptionalCGLineCapThe line cap at the end of the progress barCGLineCap.round
showTextoptionalBoolChoose whether the text at the centre is displayed or nottrue
showBottomTextoptionalBoolChoose whether the bottom text in the centre is visible (if showText is true)true

Examples

fontOne

<p float="center"> <img src="./Images/FontOne.png" /> </p>
CircularProgressView(count: count, total: total, progress: progress, fontOne: Font.title.bold())

fontTwo

<p float="center"> <img src="./Images/FontTwo.png" /> </p>
CircularProgressView(count: count, total: total, progress: progress, fontTwo: Font.title2)

colorOne

<p float="center"> <img src="./Images/ColorOne.png" /> </p>
CircularProgressView(count: count, total: total, progress: progress, colorOne: Color.blue)

colorTwo

<p float="center"> <img src="./Images/ColorTwo.png" /> </p>
CircularProgressView(count: count, total: total, progress: progress, colorTwo: Color.blue)

fill

<p float="center"> <img src="./Images/Fill.png" /> </p>
CircularProgressView(count: count, total: total, progress: progress, fill: LinearGradient(gradient: Gradient(colors: [Color.red, Color.blue]), startPoint: .leading, endPoint: .trailing))

lineWidth

<p float="center"> <img src="./Images/LineWidth.png" /> </p>
CircularProgressView(count: count, total: total, progress: progress, lineWidth: 50)

lineCap

<p float="center"> <img src="./Images/LineCap.png" /> </p>
CircularProgressView(count: count, total: total, progress: progress, lineCap: CGLineCap.square)

showText

<p float="center"> <img src="./Images/ShowText.png" /> </p>
CircularProgressView(count: count, total: total, progress: progress, showText: false)

showBottomText

<p float="center"> <img src="./Images/ShowBottomText.png" /> </p>
CircularProgressView(count: count, total: total, progress: progress, showBottomText: false)
}