此图显示了列表视图。我想隐藏使用导航链接时出现的默认公开指示器。此外,导航链接导致列表视图的颜色发生变化。我想隐藏披露按钮,并且不想修改列表单元格的颜色。如何做到这一点?
import SwiftUI
struct CurrencyHistoryView: View {
@State private var textHeight: Double = 20
let listRowPadding: Double = 5 // This is a guess
let listRowMinHeight: Double = 65 // This is a guess
var listRowHeight: Double {
max(listRowMinHeight, textHeight + 2 * listRowPadding)
}
var dataArray: [CurrencyData] = [
CurrencyData(date: "Room Rent", currency: "10000"),
CurrencyData(date: "School Fee", currency: "6000"),
CurrencyData(date: "Transport", currency: "2200"),
CurrencyData(date: "Food", currency: "4300"),
CurrencyData(date: "Electric city bill", currency: "2700"),
CurrencyData(date: "Fuel", currency: "2600"),
CurrencyData(date: "Extra", currency: "1900")
]
var body: some View {
GeometryReader { _ in
ZStack {
Color.black
VStack {
List {
Section {
ForEach(dataArray) { array in
NavigationLink(destination: Text("")) {
VStack {
HStack(alignment: .center) {
SAGenericText(textString: array.date, textColor: Color.SAColor.colorBlack100White90, textFont: SAFontConstants.getFont(for: .regular, with: .size14))
Spacer()
HStack(alignment: .bottom, spacing: 6) {
SAGenericText(textString: "Rs", textColor: Color.SAColor.colorBlack55White50, textFont: SAFontConstants.getFont(for: .regular, with: .size14))
.padding(.bottom, 1)
SAGenericText(textString: array.currency, textFont: SAFontConstants.interSemiBoldLargeText!)
}
Image(systemName: "chevron.right")
.renderingMode(.original)
}
.padding(.bottom, 5)
Rectangle().fill(Color.SAColor.colorBlack10White10).frame(height: 1)
}
}
}
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
}
}
.frame(height: CGFloat(dataArray.count) * CGFloat(self.listRowHeight))
.listStyle(GroupedListStyle())
}
.cornerRadius(7)
}
}
}
}
#Preview {
CurrencyHistoryView()
}
任何人都可以帮助实现这个目标吗?
您可以将
link
移动到透明背景中:
<#YourOriginalNavigationLinkLabel#>
.background {
NavigationLink(
destination: Text("\(array)"),
label: EmptyView.init
).opacity(0)
}
应用于您的代码:
struct CurrencyHistoryView: View {
@State private var textHeight: Double = 20
let listRowPadding: Double = 5 // This is a guess
let listRowMinHeight: Double = 65 // This is a guess
var listRowHeight: Double {
max(listRowMinHeight, textHeight + 2 * listRowPadding)
}
var dataArray: [CurrencyData] = [
CurrencyData(date: "Room Rent", currency: "10000"),
CurrencyData(date: "School Fee", currency: "6000"),
CurrencyData(date: "Transport", currency: "2200"),
CurrencyData(date: "Food", currency: "4300"),
CurrencyData(date: "Electric city bill", currency: "2700"),
CurrencyData(date: "Fuel", currency: "2600"),
CurrencyData(date: "Extra", currency: "1900")
]
var body: some View {
GeometryReader { _ in
ZStack {
Color.black
VStack {
List {
Section {
ForEach(dataArray) { array in
VStack {
HStack(alignment: .center) {
SAGenericText(textString: array.date, textColor: Color.SAColor.colorBlack100White90, textFont: SAFontConstants.getFont(for: .regular, with: .size14))
Spacer()
HStack(alignment: .bottom, spacing: 6) {
SAGenericText(textString: "Rs", textColor: Color.SAColor.colorBlack55White50, textFont: SAFontConstants.getFont(for: .regular, with: .size14))
.padding(.bottom, 1)
SAGenericText(textString: array.currency, textFont: SAFontConstants.interSemiBoldLargeText!)
}
Image(systemName: "chevron.right")
.renderingMode(.original)
}
.padding(.bottom, 5)
Rectangle().fill(Color.SAColor.colorBlack10White10).frame(height: 1)
}
.background {
NavigationLink(
destination: Text("\(array)"),
label: EmptyView.init
).opacity(0)
}
}
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
}
}
.frame(height: CGFloat(dataArray.count) * CGFloat(self.listRowHeight))
.listStyle(GroupedListStyle())
}
.cornerRadius(7)
}
}
}
}