我创建了一个 CardButton View ,并在 ContentView 中使用它:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView{
Form{
VStack(alignment: .leading){
ScrollView(.vertical, showsIndicators: true){
VStack(alignment: .leading){
NavigationLink(destination: NewScore(), label: {
CardButton(textCard: "Text1", image: "image1")
})
NavigationLink(destination: ScoreSaved(), label: {
CardButton(textCard: "Text2",image: "image2")
})
NavigationLink(destination: Analisys(), label: {
CardButton(textCard: "Text13",image: "image3")
})
}
}
}
}
.navigationBarTitle(Text("Title1"))
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
当我添加导航链接时,CardButton 构造函数中声明的图像不再显示,并在其位置出现一个蓝色圆圈。
我错了什么?
最佳答案
CardButton View 的代码:
import SwiftUI
struct CardButton: View {
var textCard: String
var image: String
init(textCard: String, image: String){
self.textCard = textCard
self.image = image
}
var body: some View {
VStack {
HStack{
Image(image)
.resizable()
.aspectRatio(contentMode: .fit)
.clipShape(Circle())
.shadow(radius: 20)
.frame(width:190,height: 190)
Text(textCard)
.font(.title)
.fontWeight(.bold)
.foregroundColor(Color.orange)
}
}
}
}
关于ios - NavigationLink 无法正确加载我的个人 View (SwiftUI),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59555852/