use*_*730 3 uinavigationbar swiftui
我在导航栏中安装了一个按钮。我已将其放置在后缘。我正在使用图像来填充按钮的标签。标签右对齐。我怎样才能将其居中?
ToolbarItem(placement: .navigationBarTrailing) {
Button {
// action
} label: {
Image(systemName: "keyboard")
}
.border(.red, width: 1)
}
Run Code Online (Sandbox Code Playgroud)
这就是默认按钮样式的工作原理。可以使用普通样式将其关闭,然后您可以根据需要设计它(就地或包装成自己的样式)
使用 Xcode 13.3 / iOS 15.4 进行测试
ToolbarItem(placement: .navigationBarTrailing) {
Button {
// action
} label: {
Image(systemName: "keyboard")
.foregroundColor(.blue).padding(4) // << here !!
}
.buttonStyle(PlainButtonStyle()) // turn off design, only behavior
.border(.red, width: 1)
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1932 次 |
最近记录: |