Skip to content

EnesKaraosman/SwiftProgress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftProgress

LinearProgress bar & CircularProgress bar for SwiftUI.

Demo GIF

Installation

Swift Package Manager

Add via https://github.com/EnesKaraosman/SwiftProgress.git

Usage

LinearProgress

// Available constructors

LinearProgress(
  progress: CGFloat, 
  foregroundColor: Color, 
  backgroundColor: Color = .clear, 
  cornerRadius: CGFloat = 8
)

LinearProgress(
  progress: CGFloat, 
  gradient: LinearGradient, 
  backgroundColor: Color = .clear, 
  cornerRadius: CGFloat = 8
)

CircularProgress

// Available constructors

CircularProgress(
  progress: CGFloat, 
  lineWidth: CGFloat, 
  foregroundColor: Color, 
  backgroundColor: Color = .clear,
  fillAxis: FillAxis = .horizontal // vertical & horizontal options
)

CircularProgress(
  progress: CGFloat, 
  lineWidth: CGFloat, 
  gradient: LinearGradient, 
  backgroundColor: Color = .clear,
  fillAxis: FillAxis = .horizontal // vertical & horizontal options
)

Full Example (reflects the demo GIF)

@State private var fillPercentage: CGFloat = 20

var body: some View {


    VStack {

        LinearProgress(
          progress: self.fillPercentage, 
          foregroundColor: .green, 
          backgroundColor: Color.green.opacity(0.2), 
          fillAxis: .vertical
        )
        .frame(width: 40, height: 100)

        LinearProgress(
            progress: self.fillPercentage,
            gradient: LinearGradient(
                gradient: .init(colors: [.yellow, .red]),
                startPoint: .leading,
                endPoint: .trailing
            ),
            backgroundColor: Color.blue.opacity(0.2),
            cornerRadius: 16
        )
        .frame(height: 50)
        .padding()

        LinearProgress(progress: self.fillPercentage, foregroundColor: Color.green.opacity(0.3))
            .clipShape(Capsule())
            .frame(height: 50)
            .padding()

        ZStack {
            LinearProgress(progress: self.fillPercentage, foregroundColor: .blue, cornerRadius: 0)
                .frame(height: 50)
                .padding()

            Text(String(format: "%1.f", self.fillPercentage))
            .font(.title)
            .foregroundColor(.pink)
            .shadow(radius: 4)
        }


        Slider(value: self.$fillPercentage, in: 0...100)
            .padding()

        HStack {
            CircularProgress(currentPercentage: self.fillPercentage, lineWidth: 8, foregroundColor: .orange)
                .rotationEffect(.degrees(-90))

            ZStack {
                CircularProgress(
                    currentPercentage: self.fillPercentage,
                    lineWidth: 16,
                    gradient: LinearGradient(
                        gradient: .init(colors: [.yellow, .red]),
                        startPoint: .leading,
                        endPoint: .trailing
                    ),
                    backgroundColor: .gray
                )

                Text(String(format: "%1.f", self.fillPercentage))
                    .font(.title)
                    .foregroundColor(.orange)
                    .shadow(radius: 8)
            }
        }.frame(height: 200)

    }
}

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy