-
Notifications
You must be signed in to change notification settings - Fork 244
/
IncreaseDecrease.swift
44 lines (37 loc) · 1.04 KB
/
IncreaseDecrease.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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())
.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()
}