gpt4 book ai didi

ios - 在没有部分的 SwiftUI 表单中添加 View

转载 作者:行者123 更新时间:2023-11-29 05:19:17 25 4
gpt4 key购买 nike

我没有成功在 Form 中添加 View 而不嵌入 Section ,所以我尝试制作 Section Section 的“不可见”设置相同背景Form有,但是有些分隔符我也必须隐藏,我发现了这个 UITableView.appearance().separatorColor = UIColor(named: "Background")它将分隔符设置为与 Form 相同的颜色背景有,但问题是这适用于整体Form我不希望那样:(

知道如何在 Form 中添加 View 吗?没有Section或如何“隐藏”该部分而不影响其他部分 SectionsForm

struct ContentView: View {

init() {
UITableView.appearance().separatorColor = UIColor(named: "Background")
}

var body: some View {

Form {
Section {
Text("text1")
Text("text2")
Text("text3")
}

Text("View without section")
.font(.title)
.listRowBackground(Color("Background"))
}
}
}

enter image description here

最佳答案

有点晚了,但可能对其他人有帮助:

  1. 将您的内容放入 VStack 中(如果您有多个元素)
  2. .listRowInset设置为EdgeInsets()
  3. 设置框架最大宽度和高度或使用垫片

使用框架:

VStack(alignment: .leading) {
Text("Title").font(.headline)
Text("Subheadline").font(.subheadline)
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.listRowInsets(EdgeInsets())
.background(Color(UIColor.systemGroupedBackground))

使用间隔(此解决方案在顶部和底部添加稍微更多的填充):

HStack {
VStack(alignment: .leading) {
Spacer()
Text("Title").font(.headline)
Text("Subheadline").font(.subheadline)
Spacer()
}
Spacer()
}
.listRowInsets(EdgeInsets())
.background(Color(UIColor.systemGroupedBackground))

enter image description here

完整代码:

NavigationView {
Form {
VStack(alignment: .leading) {
Text("Testing a title").font(.headline)
Text("Testing a subheadline").font(.subheadline)
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.listRowInsets(EdgeInsets())
.background(Color(UIColor.systemGroupedBackground))

Section(header: Text("Title and Category").bold()) {
TextField("Title", text: $title)
TextField("Category", text: $title)
}
}
.navigationTitle("Test Form")
}

关于ios - 在没有部分的 SwiftUI 表单中添加 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58832118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com