Advertisement
DeEskalator

Untitled

Feb 25th, 2025
2,898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 3.00 KB | Source Code | 0 0
  1. //
  2. //  SettingsView.swift
  3. //  SignatureUI
  4. //
  5. //  Created by Jakob  on 25.02.2025.
  6. //
  7.  
  8. import SwiftUI
  9. import SwiftData
  10.  
  11. @Model
  12. class Signature {
  13.     var owner: String
  14.    
  15.     init(owner: String) {
  16.         self.owner = owner
  17.     }
  18. }
  19.  
  20. struct SettingsView: View {
  21.     @State private var selectedSignature: Signature? = nil
  22.     @Query var signatures: [Signature]
  23.     @Environment(\.modelContext) var modelContext
  24.    
  25.     var body: some View {
  26.         TabView {
  27.             Tab("Signatures", systemImage: "signature") {
  28.                 NavigationStack {
  29.                     HStack {
  30.                         GroupBox {
  31.                             List(selection: $selectedSignature) {
  32.                                 ForEach(signatures) { signature in
  33.                                     NavigationLink(value: signature) {
  34.                                         Text(signature.owner)
  35.                                     }
  36.                                 }
  37.                             }
  38.                             .border(SeparatorShapeStyle())
  39.                             HStack {
  40.                                 Button("", systemImage: "plus") {
  41.                                     let newSignature = Signature(owner: "New Signature")
  42.                                     modelContext.insert(newSignature)
  43.                                     selectedSignature = newSignature
  44.                                    
  45.                                 }
  46.                                 .padding(.bottom, 7)
  47.                                
  48.                                 Button("", systemImage: "minus") {
  49.                                     if let selectedSignature {
  50.                                         modelContext.delete(selectedSignature)
  51.                                     }
  52.                                 }
  53.                                
  54.                                 .padding(.bottom, 10.5)
  55.                                 Spacer()
  56.                             }
  57.                             .frame(maxHeight: 10)
  58.                             .buttonStyle(.borderless)
  59.                         }
  60.                         .frame(width: 200, height: 500)
  61.                         GroupBox {
  62.                             Group {
  63.                                 if let selectedSignature {
  64.                                     SignatureView(signature: selectedSignature)
  65.                                 } else {
  66.                                     Text("Please select a signature")
  67.                                         .font(.title)
  68.                                         .foregroundStyle(.secondary)
  69.                                 }
  70.                             }
  71.                             .frame(width: 400, height: 490)
  72.                         }
  73.                     }
  74.                     .padding()
  75.                 }
  76.             }
  77.             Tab("Home", systemImage: "house") {
  78.                 // Home tab content
  79.             }
  80.         }
  81.     }
  82. }
  83.  
  84. #Preview {
  85.     SettingsView()
  86. }
  87.  
Tags: Swift UI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement