SwiftUI Xcode 12.3 无法更改工具栏中的按钮大小 [英] SwiftUI Xcode 12.3 can't change button size in toolbar
本文介绍了SwiftUI Xcode 12.3 无法更改工具栏中的按钮大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
struct ContentView: View {
var body: some View {
NavigationView {
List {
Text("Hi")
}
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
Text("Title")
.font(.headline)
}
ToolbarItem(placement: .navigationBarLeading) {
Button(action: {}) {
Image(systemName: "person.circle")
.font(.largeTitle)
}
}
}
}
}
}
Image
上的 .font(.largeTitle)
没有效果,只有当我在按钮内使用它时.
The .font(.largeTitle)
on Image
has no effect, only if I use it inside a button.
这是一个错误还是我做错了什么?
Is this a bug or am I doing something wrong?
推荐答案
看起来 SwiftUI 以不同的方式对待单个工具栏项目(应用它们自己的样式、大小等).
It looks like SwiftUI treats single toolbar items differently (applies their own style, size etc).
一种可能的解决方法是将 Button
放在更复杂的视图中,例如:如何更改SwiftUI 中带有 navigationBarLeading 位置的 ToolbarItem 的颜色
A possible workaround is to put a Button
in a more complex view, as in: How to change color of ToolbarItem with navigationBarLeading placement in SwiftUI
根据您的示例,它可能如下所示:
Adapted to your example it can look like this:
ToolbarItem(placement: .navigationBarLeading) {
HStack {
Button(action: {}) {
Image(systemName: "person.circle")
.font(.largeTitle)
}
Text("")
}
}
这篇关于SwiftUI Xcode 12.3 无法更改工具栏中的按钮大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文