A customizable gradient progress bar (UIProgressView), with full support for SwiftUI and UIKit.
Inspired by iOS 7 Progress Bar on CodePen.
To run the example project, clone this repository and open the project file from the Example directory.
- Swift 6.2
- Xcode 26
- iOS 26.0+
- iOS < 26.0 / CocoaPods / Carthage support
Use version3.x.x - iOS < 13.0 support
Use version2.x.x
Gradient Progress Bar is distributed via Swift Package Manager (SPM). Add it to your Xcode project as a package dependency or adapt your Package.swift file.
- Open your project in Xcode
- Go to File β Add Packagesβ¦
- Enter the package URL:
https://github.com/fxm90/GradientProgressBar - Choose the version rule (e.g. Up to Next Major starting at 4.0.0)
- Add the package to your target
If you manage dependencies manually, add this repository to the dependencies section of your Package.swift:
dependencies: [
.package(
url: "https://github.com/fxm90/GradientProgressBar",
from: "4.0.0"
)
]Then reference the product in your target configuration:
.product(
name: "GradientProgressBar",
package: "GradientProgressBar"
)Once the package is added, import the framework where needed:
import GradientProgressBarβ Scroll down for the UIKit documentation.
Since v2.1.0, Gradient Progress Bar provides a custom ProgressViewStyle for SwiftUI.
struct ContentView: View {
@State
private var progress = 0.5
var body: some View {
VStack {
ProgressView(value: progress)
.progressViewStyle(.gradientProgressBar)
.frame(height: 3)
Button("Update progress") {
progress += 0.1
}
}
}
}ProgressView(value: progress)
.progressViewStyle(
.gradientProgressBar(
backgroundColor: .gray.opacity(0.05),
gradientColors: [.indigo, .purple, .pink],
cornerRadius: 1.5
)
)-
backgroundColor: Color
The background color shown behind the gradient (clipped by possiblecornerRadius). -
gradientColors: [Color]
The colors used for the gradient. -
cornerRadius: CGFloat
The corner-radius used on the background and the progress bar.
To animate progress updates, add the animation(_:value:) view modifier.
ProgressView(value: progress)
.progressViewStyle(.gradientProgressBar)
.animation(.easeInOut, value: progress)Refer to Appleβs Animation documentation for more advanced customization.
β Scroll up for the SwiftUI documentation.
final class UserRegistrationViewController: UIViewController {
private let gradientProgressBar = GradientProgressBar()
// ...
override func viewDidLoad() {
super.viewDidLoad()
gradientProgressBar.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(gradientProgressBar)
NSLayoutConstraint.activate([
gradientProgressBar.leadingAnchor.constraint(equalTo: view.leadingAnchor),
gradientProgressBar.trailingAnchor.constraint(equalTo: view.trailingAnchor),
gradientProgressBar.topAnchor.constraint(equalTo: view.topAnchor),
gradientProgressBar.heightAnchor.constraint(equalToConstant: 3),
])
gradientProgressBar.progress = 0.5
}
}let gradientProgressBar = GradientProgressBar()
gradientProgressBar.animationDuration = 1
gradientProgressBar.gradientColors = [.systemIndigo, .systemPurple, .systemPink]
gradientProgressBar.timingFunction = .easeInOut-
animationDuration: TimeInterval
Controls the duration for animated updates when callingsetProgress(_:animated:). -
gradientColors: [UIColor]
The colors used for the gradient. -
timingFunction: TimingFunction
Adjusts the animation timing function for animated updates.
You can find all pre-defined timing functions here.
You can update progress just like a standard UIProgressView:
gradientProgressBar.setProgress(0.75, animated: true)or
gradientProgressBar.progress = 0.75Based on my gist, the example app demonstrates how to attach the progress bar to a UINavigationBar.
By observing the estimatedProgress property of WKWebView via Key-Value Observing, the progress bar updates automatically as the page loads.
See the example project for a complete implementation.
Felix Mau me(@)felix.hamburg
Gradient Progress Bar is released under the MIT License. See the LICENSE file for details.
