Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // SettingsView.swift
- // SignatureUI
- //
- // Created by Jakob on 25.02.2025.
- //
- import SwiftUI
- import SwiftData
- @Model
- class Signature {
- var owner: String
- init(owner: String) {
- self.owner = owner
- }
- }
- struct SettingsView: View {
- @State private var selectedSignature: Signature? = nil
- @Query var signatures: [Signature]
- @Environment(\.modelContext) var modelContext
- var body: some View {
- TabView {
- Tab("Signatures", systemImage: "signature") {
- NavigationStack {
- HStack {
- GroupBox {
- List(selection: $selectedSignature) {
- ForEach(signatures) { signature in
- NavigationLink(value: signature) {
- Text(signature.owner)
- }
- }
- }
- .border(SeparatorShapeStyle())
- HStack {
- Button("", systemImage: "plus") {
- let newSignature = Signature(owner: "New Signature")
- modelContext.insert(newSignature)
- selectedSignature = newSignature
- }
- .padding(.bottom, 7)
- Button("", systemImage: "minus") {
- if let selectedSignature {
- modelContext.delete(selectedSignature)
- }
- }
- .padding(.bottom, 10.5)
- Spacer()
- }
- .frame(maxHeight: 10)
- .buttonStyle(.borderless)
- }
- .frame(width: 200, height: 500)
- GroupBox {
- Group {
- if let selectedSignature {
- SignatureView(signature: selectedSignature)
- } else {
- Text("Please select a signature")
- .font(.title)
- .foregroundStyle(.secondary)
- }
- }
- .frame(width: 400, height: 490)
- }
- }
- .padding()
- }
- }
- Tab("Home", systemImage: "house") {
- // Home tab content
- }
- }
- }
- }
- #Preview {
- SettingsView()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement