diff --git a/AboTracker/AddSubscriptionView.swift b/AboTracker/AddSubscriptionView.swift index 74c1a29..c81c4f0 100644 --- a/AboTracker/AddSubscriptionView.swift +++ b/AboTracker/AddSubscriptionView.swift @@ -6,6 +6,7 @@ struct AddSubscriptionView: View { @State private var name: String = "" @State private var payments: [Payment] = [Payment(amount: 0, intervall: .monthly)] + @State private var color: Color = .blue var body: some View { NavigationView { @@ -14,6 +15,10 @@ struct AddSubscriptionView: View { TextField("Name", text: $name) } + Section(header: Text("Color")) { + ColorPicker("Select Color", selection: $color) + } + ForEach($payments) { $payment in Section(header: Text("Payment")) { HStack { @@ -41,7 +46,7 @@ struct AddSubscriptionView: View { Section { Button("Add Subscription") { - let newSubscription = Subscription(name: name, payments: payments) + let newSubscription = Subscription(name: name, payments: payments, color: color) subs.append(newSubscription) presentationMode.wrappedValue.dismiss() } diff --git a/AboTracker/ContentView.swift b/AboTracker/ContentView.swift index 03bf977..b8335c2 100644 --- a/AboTracker/ContentView.swift +++ b/AboTracker/ContentView.swift @@ -3,13 +3,13 @@ import SwiftUI struct ContentView: View { @State private var showAddSubscriptionSheet = false @State private var subs: [Subscription] = [ - Subscription(name: "Test", payments: [Payment(amount: 9.99, intervall: .monthly)]), - Subscription(name: "Fitness First", payments: [Payment(amount: 8, intervall: .weekly), Payment(amount: 30, intervall: .quarter)]) + Subscription(name: "Test", payments: [Payment(amount: 9.99, intervall: .monthly)], color: .blue), + Subscription(name: "Fitness First", payments: [Payment(amount: 8, intervall: .weekly), Payment(amount: 30, intervall: .quarter)], color: .red) ] var body: some View { NavigationView { - Form { + List { ForEach(subs) { sub in Section { VStack(alignment: .leading, spacing: 8) { @@ -27,6 +27,8 @@ struct ContentView: View { } .padding(.vertical, 8) } + .listRowBackground(sub.color.opacity(0.2)) + .cornerRadius(8) } .onDelete(perform: deleteSubscription) diff --git a/AboTracker/Subscription.swift b/AboTracker/Subscription.swift index 4e1785d..dbfe500 100644 --- a/AboTracker/Subscription.swift +++ b/AboTracker/Subscription.swift @@ -5,10 +5,12 @@ final class Subscription: Identifiable { public let id = UUID() var name: String var payments: [Payment] + var color: Color - init(name: String, payments: [Payment]) { + init(name: String, payments: [Payment], color: Color) { self.name = name self.payments = payments + self.color = color } func getMonthlyAmount() -> Float {