【发布时间】:2021-08-25 16:06:56
【问题描述】:
我正在尝试创建一个简单的页面,该页面具有从几个不同选项中进行选择的选项,然后在选择一个选项后显示一个文本字段和按钮。逻辑运行良好,但不幸的是,在 Form 对象和其余 UI 元素之间存在大量空白 - 有没有办法改变这种情况?
代码如下:
VStack {
Text("What would you like help with?")
.font(.largeTitle)
.fontWeight(.bold)
.multilineTextAlignment(.center)
Form {
Picker("Color", selection: $selectedIndex) {
ForEach(0 ..< arrayOfNames.count) {
Text(self.arrayOfNames[$0])
}
}
}
TextField("Enter your question", text: $question)
.opacity(selectedIndex > 0 ? 1 : 0)
.textFieldStyle(RoundedBorderTextFieldStyle())
Button(action: {}) {
Text("Ask")
}.opacity(selectedIndex > 0 ? 1 : 0)
这是一个显示问题的图像:
【问题讨论】:
-
Form是List的一种,所以使用stackoverflow.com/a/62057285/12299030这样的方法。