Search code examples
swiftuiswiftui-list

SwiftUI Question: Place text underneath(outside) of list view


I am trying to place this information underneath my list. I don't want it to be included in the list but rather it should be displayed on the view background. Sort of like the old settings in iOS 6. I've tried placing my code snippets in different spots and removing stacks snd even changing what stacks I'm using and I cant figure it out. Heres my code and a screenshot:

enter image description here

import SwiftUI

struct SettingsAboutView: View {
    var body: some View {
        List {
            // Top Section
            Section {
                HStack(spacing: 30) {
                    Spacer()
                        
                    ZStack {
                        Rectangle()
                            .frame(width: 50, height: 50)
                            .clipShape(Rectangle())
                            .shadow(radius: 2)
                            .foregroundColor(Color("PineGlade"))
                                                        
                        Image(systemName: "leaf.arrow.circlepath")
                            .resizable()
                            .frame(width: 25, height: 25)
                            .clipShape(Rectangle())
                            .foregroundColor(.white)
                                             
                    }.cornerRadius(10)
                        
                    VStack(alignment: .leading) {
                        Text("Gardn")
                            .font(.system(size: 32))
                            .fontWeight(.bold)
                            .foregroundColor(Color("ShipsOfficer"))
                                                               
                        Text("OnlyOdds.co Labs")
                            .font(.system(size: 13))
                            .fontWeight(.medium)
                            .foregroundColor(Color("ShipsOfficer"))
                    }
                        
                    Spacer()
                                
                }.padding()
                        
                NavigationLink(destination: SettingsPrivacyView()) {
                    Button(action: {
                        print("Privacy Settings")
                                
                    }) {
                        SettingsCell(title: "Privacy", imgName: "eye.slash", clr: Color("PineGlade"))
                    }
                }

                NavigationLink(destination: SettingsNotificationsView()) {
                    Button(action: {
                        print("Notification Settings")
                                
                    }) {
                        SettingsCell(title: "Notifications", imgName: "bell", clr: Color("PineGlade"))
                    }
                }
            }
           
            // Technical Info
            HStack(spacing: 62) {
                Spacer()
                
                Text("V \(UIApplication.appVersion!)")
                    .font(.system(size: 14))
                    .fontWeight(.light)
                    .foregroundColor(Color("ShipsOfficer"))
                    .opacity(0.5)
                    
                Text("Build  \(UIApplication.appBuild!)")
                    .font(.system(size: 14))
                    .fontWeight(.light)
                    .foregroundColor(Color("ShipsOfficer"))
                    .opacity(0.5)
                    
                Spacer()
            }
                
        }.listStyle(GroupedListStyle())
            .environment(\.horizontalSizeClass, .regular)
            .navigationBarTitle("Settings", displayMode: .inline)
    }
}

struct SettingsAboutView_Previews: PreviewProvider {
    static var previews: some View {
        SettingsAboutView()
    }
}

extension UIApplication {
    static var appVersion: String? {
        return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
    }
}

extension UIApplication {
    static var appBuild: String? {
        return Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String
    }
}

Solution

  • What you are looking for is a Footer. The Section View takes Footer as ViewBuilder as argument.

    Section(footer: Text("Your footer text")) {
        //Your Content here
    }
    

    You can pass Text() or create your own custom view.