我试图将 SwiftUI 标签的图像和文本垂直居中。我尝试覆盖图像的alignmentGuide,但它不起作用。有任何想法吗?
Label {
Text("Test fdasf \n adfsa dsfsd f asdf \n asd fasd fads sad fda")
} icon: {
Image(systemName: true ? "checkmark.circle.fill" : "circle")
.alignmentGuide(VerticalAlignment.top) {
$0[VerticalAlignment.center]
}
}
Run Code Online (Sandbox Code Playgroud)
Asp*_*eri 12
我们可以使用自定义标签样式来做到这一点,例如
struct DemoStyle: LabelStyle {
func makeBody(configuration: Configuration) -> some View {
HStack(alignment: .center) { // << here !!
configuration.icon
configuration.title
}
}
}
Run Code Online (Sandbox Code Playgroud)
并使用它
Label {
Text("Test fdasf \n adfsa dsfsd f asdf \n asd fasd fads sad fda")
} icon: {
Image(systemName: true ? "checkmark.circle.fill" : "circle")
}
.labelStyle(DemoStyle())
Run Code Online (Sandbox Code Playgroud)
使用 Xcode 13 / iOS 15 进行测试
| 归档时间: |
|
| 查看次数: |
3593 次 |
| 最近记录: |