Swift/SwiftUI工具栏 .principal 在工具栏和内容之间创建了尴尬的间隙。

huangapple go评论73阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月15日 13:36:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76251125.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定