在最新版本的Xcode(12)中,默认情况下,在应用程序顶部现在有一个工具栏。
我喜欢这个设计,但我还不太明白如何使用它。它似乎与普通视图的工作方式不同。
现在,我想将搜索栏添加到其中,使其在自适应布局中尽可能覆盖所有空间。但这似乎行不通。至少不像在普通的
这就是我的搜索栏现在的样子(紧挨着
这是我的主
任何反馈都非常感谢!
我喜欢这个设计,但我还不太明白如何使用它。它似乎与普通视图的工作方式不同。
![enter image description here](https://istack.dev59.com/rBiRu.webp)
View
中那样。(我必须补充说明,当涉及SwiftUI时,我还不是很有经验)。这就是我的搜索栏现在的样子(紧挨着
Button
右侧的微小蓝色东西,只有在我输入时才会扩展):这是我的主
View
中工具栏的相应代码:var body: some View {
List {
ForEach(items) { item in
if !installedOnly || item.installed {
Text("\(item.name!)")
.foregroundColor(item.installed && !installedOnly ? .green : .white)
}
}
.onDelete(perform: deleteItems)
}
.toolbar {
HStack{
TextField("", text: $search_term)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: /*@START_MENU_TOKEN@*/0/*@END_MENU_TOKEN@*/, maxHeight: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
Button(action: togglePinned) {
Label("Add Item", systemImage: installedOnly ? "pin.fill" : "pin")
}
Button(action: getApps) {
Label("Add Item", systemImage: "arrow.clockwise")
}
}
}
}
任何反馈都非常感谢!