Define macOS window size using SwiftUI

前端 未结 2 2104
情深已故
情深已故 2021-02-19 23:26

I\'m using SwiftUI to develop a new macOS application and can\'t figure out how to define the window size. In the AppDelegate, the window size is defined as shown below:

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-20 00:01

    I did do it this way. It got a startup size and resizable.

    struct windowSize {
    let minWidth : CGFloat = 100
    let minHeight : CGFloat = 200
    let maxWidth : CGFloat = 200
    let maxHeight : CGFloat = 250
    }
    
    struct ContentView : View {
      var body: some View {
        Group() {
            VStack {
                Text("Hot Stuff")
                .border(Color.red, width: 1)
                Text("Hot Chocolate")
                .border(Color.red, width: 1)
            }
        }
        .frame(minWidth: windowSize().minWidth, minHeight: windowSize().minHeight)
        .frame(maxWidth: windowSize().maxWidth, maxHeight: windowSize().maxHeight)
        .border(Color.blue, width: 1)
      }
    }
    

提交回复
热议问题