问题描述
希望找到一种方法让 NavigationView 插入符号与行的右上角对齐,而不是居中。希望找到一种方法,使插入符与我的文章标题一致。
List {
ForEach(searching ? faqTableSearch : faqTable) { section in
Section(header: Text(section.section)) {
ForEach(section.faq) { row in
NavigationLink(destination: FaqView(title: row.title,summary: row.summary,content: row.body)) {
vstack {
Text(row.title)
.font(.custom("Helvetica",size: 16))
.foregroundColor(Color(UIColor.systemGray))
.offset(x: -16)
Spacer()
Text(row.summary)
.font(.custom("Helvetica",size: 12))
.foregroundColor(Color(UIColor.systemGray))
.offset(x: 16)
}
} // end nav
} // end item
} // end section
.font(.custom("Helvetica",size: 17))
} // end loop
}
解决方法
我不认为您可以在 NavigationLink
中移动由 NavigationView
创建的标准 V 形,但是您可以隐藏默认的 NavigationLink
并使用(略有不同)重新创建它SF 符号 chevron.right
或 chevron.forward
):
struct ContentView: View {
var items = ["Item 1","Item 2","Item 3"]
var body: some View {
NavigationView {
List {
ForEach(items,id: \.self) { item in
ZStack {
NavigationLink(destination: Text("Detail")) { EmptyView() }.hidden()
VStack(alignment: .leading) {
HStack {
Text(item)
.font(.custom("Helvetica",size: 16))
.offset(x: -16)
Spacer()
Image(systemName: "chevron.right")
}.foregroundColor(Color(UIColor.systemGray))
Spacer()
Text(item)
.font(.custom("Helvetica",size: 12))
.foregroundColor(Color(UIColor.systemGray))
.offset(x: 16)
}
}
}
}
}
}
}
,
Image(systemName: "chevron.right").font(.system(size: 14)).opacity(0.3)
var body: some View {
NavigationView {
List {
Section(header: GroupHeader(title: "Example")) {
NavigationLink(
destination: UnderlineTextField_Example(),label: {
Text("TextField")
}
)
HStack {
Button("Navigation") {
isPresented.toggle()
}
.fullScreenCover(isPresented: $isPresented) {
TabNavigation()
}
Spacer()
Image(systemName: "chevron.right")
.font(.system(size: 14))
.opacity(0.3)
}
}
}