Loading Bar

Loading Bar

by dockui

Dynamic loading bar with adjustable progress control, allowing users to easily increase or decrease progress in real-time. Simple and interactive design

Platform
SwiftUI
Code
Native Swift
Format
Component
Access
Free

Code Snippet

struct ProgressView: View {
    @State private var progressValue = 0.5

    var body: some View {
        VStack {
            Text("Progress Bar")
                .font(.title).bold()
                .padding()
            
            ProgressBar(progress: progressValue, barColor: .blue)
                .frame(height: 20)
                .padding()
            
            HStack {
                // Decrease progress
                Button(action: {
                    withAnimation {
                        progressValue = max(progressValue - 0.1, 0)
                    }
                }) {
                    Text("Decrease")
                }
                .padding()
                
                Spacer()
                
                // Increase progress
                Button(action: {
                    withAnimation {
                        progressValue = min(progressValue + 0.1, 1)
                    }
                }) {
                    Text("Increase")
                }
                .padding()
            }
        }
    }
    
    // Progress bar
    struct ProgressBar: View {
        var progress: Double
        var barColor: Color
        var barHeight: CGFloat = 10

        var body: some View {
            GeometryReader { geometry in
                ZStack(alignment: .leading) {
                    Rectangle()
                        .frame(width: geometry.size.width, height: barHeight)
                        .opacity(0.3)
                        .foregroundColor(Color.gray)
                    
                    Rectangle()
                        .frame(width: min(CGFloat(progress) * geometry.size.width, geometry.size.width), height: barHeight)
                        .foregroundColor(barColor)
                        .cornerRadius(barHeight / 2)
                        .animation(.linear, value: progress)
                }
                .cornerRadius(barHeight / 2)
            }
        }
    }
}

Similar Blogs

View All Articles
How to Translate Xcode String Catalogs with AI

How to Translate Xcode String Catalogs with AI

Learn how to efficiently translate Xcode string catalogs using AI fast, streamlining localization for your iOS and SwiftUI applications.

by dockui
May 4
How to optimize your SwiftUI app in 2026

How to optimize your SwiftUI app in 2026

Discover top strategies to optimize your SwiftUI app in 2026, enhancing performance, responsiveness, and maintainability with modern concurrency.

by dockui
Apr 29
SwiftUI: iOS Confirmation Alert (Confirm + Cancel)

SwiftUI: iOS Confirmation Alert (Confirm + Cancel)

SwiftUI iOS confirmation alert with Confirm and Cancel buttons. Beginners guide to building safe actions, destructive deletes, and commit dialogs.

by dockui
Nov 11
SwiftUI: IOS Haptic Feedback Guide 2026

SwiftUI: IOS Haptic Feedback Guide 2026

Add click to vibrate haptic feedback in SwiftUI. Full guide to UIImpactFeedbackgenerator, success, error, selection, and tap vibration patterns with code.

by dockui
Nov 11

Code copied to clipboard!