每次我点击按钮时,我希望出现一个新的cardView。 我想知道在SwiftUI中是否有这种可能性,如果有,我需要执行什么操作。 如果我能够将一些参数传递给cardView结构体会更好,但任何帮助都可以。
struct ContentView: View {
var body: some View {
ZStack {
VStack {
TextButton(action: {print("Button tapped")}, text: "new card")
CardView()
}
}
}
}
struct CardView: View {
var body: some View {
ZStack {
Rectangle()
.fill(Color(#colorLiteral(red: 0.7450980544, green: 0.1568627506, blue: 0.07450980693, alpha: 1)))
.frame(width: 100, height: 100 * 1.618)
.cornerRadius(16)
.shadow(color: Color(#colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)).opacity(0.1), radius: 1, x: 0, y: 1)
.shadow(color: Color(#colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)).opacity(0.2), radius: 10, x: 0, y: 10)
VStack {
Text("Card")
.font(.system(size: 10) )
.foregroundColor(.white)
.bold()
}
}
}
}
struct TextButton: View {
let action: () -> Void
let text: String
var body: some View {
Button(action: action, label: {
Text(text)
.padding(.horizontal, 16)
.padding(.vertical, 16)
.foregroundColor(.white)
.background(Color.blue)
.cornerRadius(.infinity)
.shadow(color: Color(#colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)).opacity(0.1), radius: 1, x: 0, y: 1)
.shadow(color: Color(#colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)).opacity(0.2), radius: 10, x: 0, y: 10)
})
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
} ```