我只是想在用戶單擊按鈕時打開一個新視圖。使用 Swift API 執行此操作的最簡單、最簡單的方法是什么?
//Login Button
Button(
action:
{
// Open Signup Screen
Signup();
},
label:
{
// How the button looks li
Text("Create New Account")
.foregroundColor(.white)
.font(.title)
}
)
.frame(maxWidth: .infinity, alignment: .center)
.background(Color(red: 0.22, green: 0.655, blue: 0.02))
.cornerRadius(8)
.padding(.horizontal, metrics.size.width*0.10)
}
謝謝。
以賽亞·湯普森
uj5u.com熱心網友回復:
最好的方法是使用 aNavigationLink并將內容包裝在NavigationView.
將NavigationView用于表示視圖層次結構。
例如:
// Wrapper for LogIn
struct ContentView: View {
var body: some View {
NavigationView { LogIn() }
}
}
// LogIn
struct LogIn: View {
var body: some View {
VStack {
// Fields for log in
NavigationLink(destination: SignUp()) {
Text("Create New Account")
.foregroundColor(.white)
.font(.title)
.frame(maxWidth: .infinity, alignment: .center)
.background(Color(red: 0.22, green: 0.655, blue: 0.02))
.cornerRadius(8)
.padding(.horizontal, metrics.size.width*0.10)
}
}
}
}
您可以在官方檔案中找到更多資訊:
- 導航視圖
- 導航鏈接
另外 [Hacking With Swift] ( https://www.hackingwithswift.com/quick-start/swiftui/displaying-a-detail-screen-with-navigationlink ) 是 SwiftUI 的一個很好的資源
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/396574.html
上一篇:基于行數問題的表視圖寬度
