Pet*_*ert 5 xcode swift swiftui swiftui-navigationlink
我创建了一个由滚动视图中的视图组成的自定义菜单。
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)
}
}
Run Code Online (Sandbox Code Playgroud)
然后我将视图包装在 NavigationLink 中以转到所需的目的地:
NavigationLink(destination: PanicDiaryEducationView()) {
InformationDetailView(title: "Changing behaviour", subTitle: "How to use the behavioural experiments feature", imageName: "questionmark.circle.fill")
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,这样做会导致副标题文本(可能还有标题)居中,而不是默认的前导对齐。使用.frame(alignment : .topLeading)不会改变它。
当未正确包装在NavigationLinkIt 格式中时。
如何阻止它使文本居中?
Asp*_*eri 11
这是关于默认多行文本对齐方式的问题。与 SwiftUI 中的许多默认值一样,它通常并不明显。所以最好明确一下。所以这是一个修复:
Text(subTitle)
.font(.body)
.multilineTextAlignment(.leading) // << here !!
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1253 次 |
| 最近记录: |