如何在 swiftui 中通过按钮操作在视图控制器之间导航?
How to navigate between view controllers on a button action in swiftui?
我想借助按钮操作在登录屏幕和注册屏幕之间导航。
Button(action: {
NavigationLink(destination:SignUpScene()){
Text("Show Detail View")
}
print("Join button tapped!!")
})
您可以创建导航 link 并设置属性使其像按钮一样显示:
这是我的代码:
var body: some View {
NavigationView {
//Button to navigate to another page
NavigationLink(destination: AlertView()) {
Text("GO TO ALERT")
.padding(15)
.frame(minWidth: 0, maxWidth: .infinity)
.background(Color.red)
.foregroundColor(Color.white)
.cornerRadius(4)
}
.padding([.leading, .trailing], 30)
.padding([.top], 21)
.frame(height: 50)
}
}
外观如下:
希望对您有所帮助..祝您好运:)
我想借助按钮操作在登录屏幕和注册屏幕之间导航。
Button(action: {
NavigationLink(destination:SignUpScene()){
Text("Show Detail View")
}
print("Join button tapped!!")
})
您可以创建导航 link 并设置属性使其像按钮一样显示: 这是我的代码:
var body: some View {
NavigationView {
//Button to navigate to another page
NavigationLink(destination: AlertView()) {
Text("GO TO ALERT")
.padding(15)
.frame(minWidth: 0, maxWidth: .infinity)
.background(Color.red)
.foregroundColor(Color.white)
.cornerRadius(4)
}
.padding([.leading, .trailing], 30)
.padding([.top], 21)
.frame(height: 50)
}
}
外观如下:
希望对您有所帮助..祝您好运:)