我創建了一個由滾動視圖中的視圖組成的自定義選單。
struct MenuInformationDetailView: View {
var title: String = "title"
var subTitle: String = "subTitle"
var imageName: String = "exclamationmark.circle.fill"
var body: some View {
HStack(alignment: .center) {
Image(systemName: imageName)
.font(.largeTitle)
.foregroundColor(.white)
.padding()
.accessibility(hidden: true)
VStack(alignment: .leading) {
Text(title)
.font(.headline)
.foregroundColor(.white)
.accessibility(addTraits: .isHeader)
Text(subTitle)
.font(.body)
.foregroundColor(.white)
.opacity(0.8)
.fixedSize(horizontal: false, vertical: true)
}
}
.padding(.top)
}
}
然后我將視圖包裝在 NavigationLink 中以前往所需的目的地:
NavigationLink(destination: PanicDiaryEducationView()) {
InformationDetailView(title: "Changing behaviour", subTitle: "How to use the behavioural experiments feature", imageName: "questionmark.circle.fill")
}
出于某種原因,這樣做會導致字幕文本(可能還有標題)居中,而不是默認的前導對齊方式。使用.frame(alignment : .topLeading)不會改變它。
如果未正確包裝在NavigationLinkIt 格式中。
如何阻止它使文本居中?

uj5u.com熱心網友回復:
這與默認的多行文本對齊有關。與 SwiftUI 中的許多默認設定一樣,它通常并不明顯。所以最好把它說清楚。所以這里有一個修復:
Text(subTitle)
.font(.body)
.multilineTextAlignment(.leading) // << here !!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/459930.html
標籤:迅速 代码 迅捷 swiftui-导航链接
