Repository navigation
Expand file tree
/
Copy pathContentView.swift
More file actions
167 lines (142 loc) · 5.91 KB
/
Copy pathContentView.swift
File metadata and controls
167 lines (142 loc) · 5.91 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import SwiftUI
struct ContentView: View {
@State private var items: [String] = []
@State private var newItem: String = ""
@State private var selectedItem: String? = nil
@State private var ratings: [String: Int] = [:] // Dictionary to store ratings for each item
@State private var showSummary: Bool = false
@State private var budget: String = "0" // State variable for budget
var body: some View {
NavigationView {
ZStack{
Color(.white)
.ignoresSafeArea()
VStack {
Image("twocentslogo")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width:150, height:150)
.border(.green)
.cornerRadius(10)
.padding(10)
VStack {
Text("How much would you like to spend?: ")
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(/*@START_MENU_TOKEN@*/.blue/*@END_MENU_TOKEN@*/)
TextField("Enter budget", text: $budget)
.frame(width: 300, height: 75)
.font(.system(size:30))
.keyboardType(.decimalPad) // Ensures numeric keypad for input
.textFieldStyle(RoundedBorderTextFieldStyle())
.foregroundColor(.green)
}
.padding(.horizontal)
Text("We want to get to know you! Enter your purchasing priorites. What do you prioritize?")
.padding()
.border(.green)
.foregroundColor(.blue)
.cornerRadius(10)
.font(.system(size: 20))
.fontWeight(.bold)
HStack {
TextField("Enter priorities", text: $newItem, onCommit: addItem)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
.font(.system(size:25))
Button(action: addItem) {
Text("Add")
.fontWeight(.bold)
.font(.system(size:15))
.padding(5)
.border(.purple)
.cornerRadius(10)
}
.padding()
.font(.system(size:10))
.background(Color.green)
.cornerRadius(50)
}
.padding()
List {
ForEach(items, id: \.self) { item in
ItemRow(item: item, rating: $ratings[item])
}
.onDelete(perform: deleteItem)
}
NavigationLink(destination: newfeatureview()) {
Text("Check Info")
.font(.title2)
.padding()
.frame(maxWidth: .infinity)
.background(Color.yellow)
.foregroundColor(.black)
.cornerRadius(10)
.padding()
}
}
.navigationBarItems(trailing: HStack {
Text("Budget: $\(budget)") // Display budget in the corner
.font(.system(size: 25))
.fontWeight(.bold)
.foregroundColor(.blue)
.padding()
EditButton()
.font(.system(size:25))
})
}
}
}
private func addItem() {
if !newItem.isEmpty {
items.append(newItem)
newItem = "" // Clear the text field after adding the item
}
}
private func deleteItem(at offsets: IndexSet) {
items.remove(atOffsets: offsets)
}
}
struct ItemRow: View {
let item: String
@State private var isExpanded: Bool = false
@Binding var rating: Int?
var body: some View {
VStack {
HStack {
Text(item)
Spacer()
if let rating = rating {
Text("Rating: \(rating)")
.foregroundColor(.gray)
}
Button(action: {
withAnimation {
isExpanded.toggle()
}
}) {
Image(systemName: isExpanded ? "chevron.up" : "chevron.down")
.foregroundColor(.blue)
}
}
.padding()
if isExpanded {
Picker("Rate \(item)", selection: $rating) {
Text("1").tag(1 as Int?)
Text("2").tag(2 as Int?)
Text("3").tag(3 as Int?)
}
.pickerStyle(SegmentedPickerStyle())
.padding()
}
}
.background(Color(UIColor.systemGroupedBackground))
.cornerRadius(10)
.padding(.vertical, 5)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}