0

I am using this code for help Xcode to build my Window Size as big as the screen of mac, but it does not get maxed! How we can read the size of screen and set it for view size for taking all available space on screen? It would be great getting a SwiftUI approach for the issue.

struct ContentView: View {

    var body: some View {
        
        Color.purple
            .frame(maxWidth: .infinity, maxHeight: .infinity)

    }
    
}
Mada
  • 11
  • 3

1 Answers1

0
    let screenSize = NSScreen.main?.frame.size ?? CGSize(width: 800, height: 600)
    
    Color.purple
        .frame(width: screenSize.width, height: screenSize.height)
ChrisR
  • 3,983
  • 1
  • 3
  • 17
  • It is not 100% SwiftUI, but it is better than nothing. thanks – Mada Feb 21 '22 at 15:29
  • yeah, I don't know of a pure SwiftUI solution yet.e.g. would be nice to maximize a window to full screen programmatically ... – ChrisR Feb 21 '22 at 15:41
  • Yes, that would be nice some view that can full all available space of screen like iOS. – Mada Feb 21 '22 at 17:20