【问题标题】:SwiftUI Question: Place text underneath(outside) of list viewSwiftUI 问题:将文本放在列表视图的下方(外部)
【发布时间】:2020-06-15 06:55:25
【问题描述】:

我正在尝试将此信息放在我的列表下方。我不希望它包含在列表中,而是应该显示在视图背景上。有点像 iOS 6 中的旧设置。我尝试将我的代码 sn-ps 放在不同的位置并删除堆栈,甚至更改我正在使用的堆栈,但我无法弄清楚。这是我的代码,我附上了截图https://i.stack.imgur.com/PcUgJ.png 以供参考。感谢任何可以帮助我的菜鸟的人。

我的代码:

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

    }

}

【问题讨论】:

  • 您是否尝试将version cell 的背景颜色更改为不存在的颜色?

标签: swiftui swiftui-list


【解决方案1】:

您正在寻找的是页脚。 Section View 将 Footer 作为 ViewBuilder 作为参数。

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

您可以传递Text() 或创建自己的自定义视图。

【讨论】:

  • 谢谢!这就是我需要的!我知道这很简单,但想不通。
  • @PoonDopolis 没问题。还必须阅读他们的文档,只是从旧的 Objective C 时代才知道的,从来没有为 SwiftUI 查找过。
【解决方案2】:

只需将 List 放入 VStack 并放入 文本(你的文本)

在列表下

【讨论】:

  • 我试过了,但我一直收到关于我的导航栏标题的错误
猜你喜欢
  • 1970-01-01
  • 2020-11-29
  • 1970-01-01
  • 1970-01-01
  • 2021-11-20
  • 2016-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多