20 C
Canberra
Sunday, December 14, 2025

Customized ProgressView in a SwiftUI widget


I’m attempting so as to add a linear ProgressView to a SwiftUI Widget that counts up over time and makes use of a LinearGradient as an alternative of a stable coloration for the progress bar.

First I attempted utilizing the built-in ProgressView with a ProgressViewStyle however I discover that it stops counting up after I add the ProgressViewStyle:

ProgressView(
    timerInterval: (.now...endDate),
    countsDown: false,
    label: {EmptyView()},
    currentValueLabel: {
        EmptyView()
    }
)
.progressViewStyle(
    GradientLinearProgressViewStyle(
        gradient: LinearGradient(
            colours: [.red, .green],
            startPoint: .main,
            endPoint: .trailing
        )
    )
)

In its place, I attempted masking a LinearGradient with a ProgressView, which does animate accurately:

Capsule()
    .fill(
        LinearGradient(
            colours: [.green.opacity(0.3), .red],
            startPoint: .main,
            endPoint: .trailing
        )
    )
    .masks(alignment: .main) {
        ProgressView(
            timerInterval: (.now...endDate),
            countsDown: false,
            label: { EmptyView() },
            currentValueLabel: { EmptyView() }
        )
        .scaleEffect(y: 7, anchor: .middle)
    }

This strategy restores the animation, nevertheless it introduces an undesirable gradient background behind the progress bar like so: Customized ProgressView in a SwiftUI widget

Is there a correct or really helpful approach to create a customized linear ProgressView with a gradient in a SwiftUI widget with out breaking the timer-based animation or introducing background artifacts?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles