Saj*_*jon 4 swift swiftui xcode12
我正在使用 SwiftUI 的全新Label
视图,在 Big Sur 上运行 Xcode 12 beta。
作为图像,我使用SF Symbol并找到了一个名为"play"
. 但是我注意到没有任何边界像素的自定义图像存在同样的问题(即间距不是由图像引起的),例如 PDF 图标,所以它可能与图像无关。
在 Apple 的演示中,文本和图像应该自动正确对齐,但我没有看到。
struct ContentView: View {
var body: some View {
Label("Play", systemImage: "play")
}
}
Run Code Online (Sandbox Code Playgroud)
结果如下:
任何想法为什么图像(图标)和文本垂直未对齐?
如果我们给 Button 一个背景色,我们就能更准确地看到错位:
Label("Play", systemImage: "play")
.background(Color.red)
Run Code Online (Sandbox Code Playgroud)
结果如下:
Asp*_*eri 10
可能是一个错误,因此值得向 Apple 提交反馈。同时这里是基于自定义标签样式的工作解决方案。
使用 Xcode 12b 测试
struct CenteredLabelStyle: LabelStyle {
func makeBody(configuration: Configuration) -> some View {
HStack {
configuration.icon
configuration.title
}
}
}
struct TestLabelMisalignment: View {
var body: some View {
Label("Play", systemImage: "play")
.labelStyle(CenteredLabelStyle())
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1621 次 |
最近记录: |