article

Monday, August 9, 2021

SwiftUI Simple Progress View

SwiftUI Simple Progress View

A progress view is a view that shows the progress towards completion of a task.
ContentView.swift
 
//
//  ContentView.swift
//  swiftuidev
//
//  Created by Cairocoders
//

import SwiftUI

struct ContentView: View {

    @State private var progress = 0.0
    
    var body: some View {
        
        VStack(spacing: 30) {
            HStack {
                VStack {
                    ProgressView("Progress", value: progress, total: 100)
                        .accentColor(Color.green)
                        .padding([.leading, .trailing], 10)
                        .scaleEffect(x: 1, y: 4, anchor: .center)
                    
                    Button("Increment Progress") {
                        if progress < 100 {
                            progress += 10
                        }
                    }
                    .padding(.top)
                    .padding()

                    Text("Current Progress: \(Int(progress))%")
                        .padding()
                    
                }
            }
            
            HStack {
                VStack {
                    ProgressView()
                        .scaleEffect(1.5, anchor: .center)
                        .progressViewStyle(CircularProgressViewStyle(tint: .blue))
                    
                }
            }
        }
        .padding(.all, 10)
        
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Related Post