我試圖將 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]
}
}

uj5u.com熱心網友回復:
我們可以使用自定義標簽樣式來做到這一點,比如
struct DemoStyle: LabelStyle {
func makeBody(configuration: Configuration) -> some View {
HStack(alignment: .center) { // << here !!
configuration.icon
configuration.title
}
}
}
并使用它
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())

使用 Xcode 13 / iOS 15 測驗
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/334834.html
