我的问题是如何在不更改UI的情况下将NavigationLink添加到下面的代码。我尝试了几个小时,但不幸的是没有成功。因此,如果有人可以帮助我,那将是很好。我也找到了this,但不幸的是,答案对我没有用。也许我做错了事
import SwiftUI
struct ContentView: View {
var body: some View {
UITableView.appearance().separatorStyle = .none
return NavigationView {
List {
CardView()
.listRowInsets(EdgeInsets())
}
.navigationBarTitle("Title")
}
}
}
struct CardView: View {
var body: some View {
VStack {
// NavigationLink(destination: EmptyView()) {
Image("Image")
.resizable()
.aspectRatio(contentMode: .fit)
HStack {
VStack(alignment: .leading) {
Text("Title")
.font(.system(size: 20))
.fontWeight(.semibold)
.foregroundColor(.primary)
.lineLimit(3)
Text("Subtitle")
.font(.caption)
.foregroundColor(.secondary)
}
.layoutPriority(100)
Spacer()
Image(systemName: SFSymbolName.chevron_right)
.foregroundColor(.secondary)
.font(Font.body.weight(.semibold))
}
.padding([.leading,.bottom,.trailing],16)
.padding(.top,5)
// }
}
.background(Color("CustomCardViewColor"))
.cornerRadius(10)
.padding(.all,0.1)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(Color(.sRGB,red: 150/255,green: 150/255,blue: 150/255,opacity: 0.1),lineWidth: 1)
)
.padding([.top,.leading,.trailing])
}
}