gpt4 book ai didi

ios - SwiftUI 无法删除选择器上方的空间 - 表单版本

转载 作者:行者123 更新时间:2023-12-01 15:55:14 26 4
gpt4 key购买 nike

SwiftUI 无法删除选择器上方的空间 - 表单版本

我在 SwiftUI 中为选择器的格式苦苦挣扎。我建立了一个简单的
在单个 View 应用程序中带有一些其他 View 的选择器。 Header 之间有一个空格
和我无法删除的选择器。我会满足于将灰色设置为白色。如果
我改变了选择器的框架,它只是挤压了选择器 - 灰色空间仍然存在
未受影响。我不知道该怎么称呼那个空间——它似乎不是一部分
Header、Picker、Form 或 Section。

我发现的对这个问题的唯一引用是文章 57851878,它建议把
标题本身中的 View 。这是行不通的,无论如何都是一个非常糟糕的主意。

图中勾勒出的红色空间为主体:

enter image description here

这是代码:

struct ContentView: View {

@State private var thing: String = ""
@State private var enableSaveButton = false
@State private var selection = 0
@State private var selection2 = 0

var things = ["books","desks","chairs","lamps","couches","shelves"]

var body: some View {
NavigationView {
//ScrollView{
VStack {
Group {//first group
VStack {
Text("Text at the Top")
TextField("enter something here", text: $thing)
.frame(width:350, height: 50)
.clipShape(RoundedRectangle(cornerRadius: 12))
.overlay(RoundedRectangle(cornerRadius: 12)
.stroke(Color.gray, lineWidth: 2))
.padding(.leading, 5)
.padding(.bottom, 20)

Section(header: HStack {
Text("This is the Header")
.font(.headline)
.foregroundColor(.blue)
.padding(.bottom, 0)
.padding(.leading, 30)
Spacer()
}
.background(Color.white)
.listRowInsets(EdgeInsets(
top: 0,
leading: 0,
bottom: 0,
trailing: 0))
) {

Form {
Text("This is the Chosen Thing: \(self.things[selection2])")

Picker(selection: self.$selection2, label: Text("Choose Thing").foregroundColor(.blue)) {
ForEach(0 ..< things.count) {
Text(self.things[$0])
}
}//picker
}//form
.frame(width:350, height: 115)
.padding(.top, 0)
}//first picker section
}//vstack
}//first group

Spacer()

Group {//second Group
Text("Enable and Disable this button")
Button(action: {
print("whatever")
} ) {
ZStack {
RoundedRectangle(cornerRadius: 20)
.fill(Color.yellow)
.frame(width: 100, height: 40)
Text("Save").font(.headline)
}
}
.shadow(radius: 12, x: 10, y: 10)
//.disabled(!enableSaveButton)
}//second Group
}//outer VStack
//}//Scrollview
.navigationBarTitle("Things")
}//nav view
}//body
}

Any guidance would be appreciated. Xcode 11.2.1 (11B500)

最佳答案

您可以删除 upperlower 的空间Form 通过添加以下代码

struct ContentView: View {

init() {
UITableView.appearance().tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: Double.leastNonzeroMagnitude))
UITableView.appearance().tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: Double.leastNonzeroMagnitude))
}

//your code .....
}

关于ios - SwiftUI 无法删除选择器上方的空间 - 表单版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59278224/

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