A ProgressCard is an elementary element giving a good and concise representation of the amount of progress using a title, a progress bar, and additional details for consumed and balance values. The structure of this card allows for flexibility and customization based on input parameters for dynamically modifying content and styling.
struct ProgressCardV: View {
let title0fView: String
let totalValue: Float
let consumeTitle: String
let consumeValue: Float
let balanceTitle: String
let balanceValue: Float
let progressColor: Color
var progressValue: Double {
totalValue > 0 ? Double(consumeValue) / Double(totalValue) : 0
}
var viewModel: LeaveDetailViewModel?
}
The card uses a ZStack for layering and a VStack for vertical alignment of content:
var body: some View {
ZStack {
VStack(alignment: .leading, spacing: 8) {
// Type and Total
HStack {
Text(title0fView.uppercased())
.font(.headline)
.foregroundStyle(.themePurple)
Spacer()
Text("\(String(format: "%.1f", totalValue))")
.font(.title)
.bold()
} // .foregroundStyle(.black) // Note: This is commented out in the image
}
}
}
ProgressView: Displays a horizontal progress bar.
ProgressView(value: progressValue)
.frame(height: 12)
.progressViewStyle(LinearProgressViewStyle(tint: progressColor))
.clipShape(Capsule())
.animation(.easeInOut(duration: 0.5), value: progressValue)
Labels:
HStack {
Label {
VStack(alignment: .leading, spacing: 2) {
Text("\(consumeTitle)")
.font(.caption)
.foregroundColor(Color(uiColor: .darkGray))
Text("\(String(format: "%.1f", consumeValue))")
.font(.headline)
.foregroundColor(progressColor)
.bold()
}
} icon: {} // Empty icon
Circle()
.fill(progressColor)
.frame(width: 12, height: 12)
Spacer()
Label {
VStack(alignment: .leading, spacing: 2) {
Text(balanceTitle)
.font(.caption)
.foregroundColor(Color(uiColor: .black))
Text("\(String(format: "%.1f", balanceValue))")
.font(.headline)
.foregroundColor(Color(uiColor: .black)) // Note: .black is redundant here, it's already black from the line above
.bold()
}
} icon: {} // Empty icon
Circle()
.fill(Color(uiColor: .darkGray))
.frame(width: 12, height: 12)
}
The RoundedRectangle gives the card its characteristic shape, with shadows for a lifted appearance.
.padding(12)
.background(
RoundedRectangle(cornerRadius: 10)
.fill(Color.white)
.shadow(color: gray.opacity(0.2), radius: 5, x: 0, y: 5)
)
When this component is used, it will generate a card like the following:
Example Usage:
ProgressCardV(
title0fView: "Leave Balance",
totalValue: 30,
consumeTitle: "Consumed",
consumeValue: 10,
balanceTitle: "Balance",
balanceValue: 20,
progressColor: .blue // Or another Color value
)
Ready to transform your business with our technology solutions? Contact Us today to Leverage Our iOS Expertise.