AutorÃa | Ultima modificación | Ver Log |
//// ProgressBarView.swift// twogetskills//// Created by Efrain Yanez Recanatini on 5/5/22.//import SwiftUIstruct ProgressBar: View {private let value: Doubleprivate let maxValue: Doubleprivate let backgroundEnabled: Boolprivate let backgroundColor: Colorprivate let foregroundColor: Colorinit(value: Double,maxValue: Double,backgroundEnabled: Bool = true,backgroundColor: Color = Color(UIColor(red: 245/255,green: 245/255,blue: 245/255,alpha: 1.0)),foregroundColor: Color = Color.black) {self.value = valueself.maxValue = maxValueself.backgroundEnabled = backgroundEnabledself.backgroundColor = backgroundColorself.foregroundColor = foregroundColor}var body: some View {// 1ZStack {// 2GeometryReader { geometryReader in// 3if self.backgroundEnabled {Capsule().foregroundColor(self.backgroundColor) // 4}Capsule().frame(width: self.progress(value: self.value,maxValue: self.maxValue,width: geometryReader.size.width)) // 5.foregroundColor(self.foregroundColor) // 6.animation(.easeIn) // 7}}}private func progress(value: Double,maxValue: Double,width: CGFloat) -> CGFloat {let percentage = value / maxValuereturn width * CGFloat(percentage)}}struct ProgressBar_Previews: PreviewProvider {static var previews: some View {ProgressBar(value: 50, maxValue: 100)}}