Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Created November 24, 2024 00:39
Show Gist options
  • Save amosgyamfi/1fba54443b1fcbdde07069a926d2671a to your computer and use it in GitHub Desktop.
Save amosgyamfi/1fba54443b1fcbdde07069a926d2671a to your computer and use it in GitHub Desktop.
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