Created
November 24, 2024 00:39
-
-
Save amosgyamfi/1fba54443b1fcbdde07069a926d2671a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct IncreaseDecrease: View { | |
@State private var rating: Int = 0 | |
var body: some View { | |
HStack(spacing: 20) { | |
// Decrease button | |
Button("Decrease", systemImage: "minus.circle") { | |
withAnimation { | |
rating -= 1 | |
} | |
} | |
.disabled(rating == 0) | |
Spacer() | |
// Rating display | |
Text(rating, format: .number) | |
.contentTransition(.numericText(value: Double(rating))) | |
.font(.title) | |
.bold() | |
.disabled(rating == 10) | |
Spacer() | |
// Increase button | |
Button("Increase", systemImage: "plus.circle") { | |
withAnimation { | |
rating += 1 | |
} | |
} | |
.disabled(rating == 10) | |
} | |
.padding() | |
.background(RoundedRectangle(cornerRadius: 10).fill(Color.white)) | |
.shadow(radius: 5) | |
.padding() | |
} | |
} | |
#Preview { | |
IncreaseDecrease() | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment