I am using the same ContentView once with @main and once with a main file. When I use the main file, I am unable to see the plus button. Also, the style of the window is different in each case. I want the same window style as the @main method, and I want my plus button to be visible. How can I solve this problem? I see a padding in Window buttons in @main.
import SwiftUI
@main
struct TestApp: App {
var body: some Scene {
WindowGroup("Test") {
ContentView()
}
}
}
struct ContentView: View {
var body: some View {
NavigationView {
List {
Text("Item 1")
Text("Item 2")
Text("Item 3")
}
.toolbar {
ToolbarItem {
Button(action: { print("action") }) {
Label("Add Item", systemImage: "plus")
}
}
}
Text("Select an item")
}
}
}
import Cocoa
import SwiftUI
class AppDelegate: NSObject, NSApplicationDelegate {
private lazy var window: NSWindow = NSWindow()
func applicationDidFinishLaunching(_ aNotification: Notification) {
window.styleMask = [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView]
window.backingType = .buffered
window.isReleasedWhenClosed = false
window.center()
window.setFrameAutosaveName("Main Window")
window.title = "Test"
window.isMovableByWindowBackground = true
window.contentView = NSHostingView(rootView: ContentView())
window.makeKeyAndOrderFront(window)
}
}
struct ContentView: View {
var body: some View {
NavigationView {
List {
Text("Item 1")
Text("Item 2")
Text("Item 3")
}
.toolbar {
ToolbarItem {
Button(action: { print("action") }) {
Label("Add Item", systemImage: "plus")
}
}
}
Text("Select an item")
}
}
}