[英]How to add space in toolbar items (SwiftUI)
Spacer() 在 ToolbarItem 中没有效果,我想让项目分散而不是聚集。 你知道如何解决这个问题吗? 谢谢你。
这是代码。
struct ContentView: View {
var body: some View {
NavigationView {
VStack{
Image("searchbar")
Text("Test")
}
.toolbar {
ToolbarItem(placement: .principal) {
HStack {
Text("9scoretrain")
Spacer()
NavigationLink(
destination: Text("SearchView"),
label: {
Image("searchbar")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width:200)
})
Spacer()
NavigationLink(
destination: Text("CameraView"),
label: {
Image(systemName: "camera.viewfinder")
})
}
}
}
}
}
}
此方法可能会解决,但居中项目和尾随项目之间仍有一些空间。
这仍然不是我想要的,我希望物品均匀分布。
这是代码。
struct ContentView: View {
var body: some View {
NavigationView {
VStack{
Image("searchbar")
Text("Test")
}
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Text("9scoretrain")
}
ToolbarItem(placement: .principal) {
NavigationLink(
destination: Text("SearchView"),
label: {
Image("searchbar")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width:200)
})
}
ToolbarItem(placement: .navigationBarTrailing) {
NavigationLink(
destination: Text("CameraView"),
label: {
Image(systemName: "camera.viewfinder")
})
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.