Goal: Add buttons to navigation bar on a real SwiftUI for MacOS (not Catalyst)
What I did: Tried navigationBarItem, but found it's not available for MacOS.
Does anyone have a solution? Browsed all possible MacOS SwiftUi projects and didn't find anything simulation. Should be trivial, as this is a very common use case?
import SwiftUI
struct SwiftUIView: View {
var body: some View {
NavigationView {
Text("Hello, World!")
.navigationBarItems()
}
}
}
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
SwiftUIView()
}
}
There is no such thing in macOS. You could use the NavigationLink. Check the following code:
struct ContentView: View {
var body: some View {
NavigationView {
NavigationLink(destination: Text("Detail").frame(maxWidth: .infinity, maxHeight: .infinity)) {
Text("Hello, World!")
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.