How can I set the width of a window that shall be resizable with a Button in MacOS SwiftUI? I tried with the frame modifier, but that sets the width permanently. I want the user to be able to drag the Sitze with the mouse and set a predefined size via a Button.
struct ResizeTest: App {
var body: some Scene {
WindowGroup {
ContentView()
.frame(minWidth: 200, maxWidth: 1000)
.padding(0)
}
.defaultSize(width: 300, height: 400)
.windowResizability(.contentSize)
}
}
struct ContentView: View {
@State var width = 400.0
var body: some View {
VStack (alignment: .center) {
Text("width: \(width)")
Button("600"){ width = 600}
}
.frame(width:width )
.background(Color.green)
}
}
.frame(minWidth: 200, maxWidth: 1000)