英文:
Swift/SwiftUI toolbar .principal creates awkward gap between toolbar and content
问题
I was wondering why there was a strange gap between my toolbar and the content of the view and have realised it is caused by the .principal placement of items in the toolbar. Any other placement doesn't cause the same gap to occur.
In the toolbar, I want one item to be centered and another two on each side in the corner. I just don't want that strange gap.
struct AnotherTest: View {
var body: some View {
NavigationView {
VStack {
Text("Hello, World!")
Spacer()
}
.toolbar {
ToolbarItem(placement: .principal) {
Text("testing")
}
}
}
}
}
英文:
I was wondering why there was a strange gap between my toolbar and the content of the view and have realised it is caused by the .principal placement of items in the toolbar. Any other placement doesn't cause the same gap to occur.
In the toolbar, I want one item to be centred and another two on each side in the corner. I just don't want that strange gap.
struct AnotherTest: View {
var body: some View {
NavigationView {
VStack {
Text("Hello, World!")
Spacer()
}
.toolbar {
ToolbarItem(placement: .principal) {
Text("testing")
}
}
}
}
}
答案1
得分: 1
.navigationBarTitleDisplayMode(.inline) as per @HunterLion
根据 @HunterLion,.navigationBarTitleDisplayMode(.inline)
英文:
.navigationBarTitleDisplayMode(.inline) as per @HunterLion
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论