HeadlinesBriefing favicon HeadlinesBriefing.com

SwiftUI ProgressView: Building Progress Bars

DEV Community •
×

Apple's SwiftUI framework includes a native ProgressView component for displaying progress bars and activity indicators. Developers can create a basic bar using the `init(_:value:total:)` initializer, where `value` tracks current progress and `total` defines the endpoint, typically ranging from 0.0 to 1.0. A simple implementation uses a `@State` variable to drive the visual update.

The component offers multiple built-in styles. The `progressViewStyle(_:)` modifier accepts structures conforming to the `ProgressViewStyle` protocol, with default options including `automatic`, `circular`, and `linear`. For indeterminate tasks, calling `ProgressView()` without arguments generates a standard activity spinner, a common pattern for signaling background processes without a defined duration.

Advanced usage includes automatic timers. The `init(timerInterval:countsDown:)` initializer accepts a date range, creating a ProgressView that updates automatically. This is ideal for workout timers or any timed operation where the UI must reflect elapsed time without manual state management. It simplifies building time-sensitive interfaces directly within SwiftUI.