In Cocoa, you can find out whether or not you have a Retina screen with the backingScaleFactor property like the following.
func getWinFactor() -> CGFloat? {
if let view = self.view.window {
let factor = view.backingScaleFactor
return factor
} else {
return nil
}
}
How could we detect whether or not the application is dealing with a Retina screen in SwiftUI? I thought the displayScale Environment property is the chosen one. But my 27-inch iMac with a Retina display will return the scale as 1.0.
import SwiftUI
struct ContentView: View {
@Environment(\.displayScale) var displayScale
var body: some View {
VStack {
...
}
.onAppear {
print("display scale: \(displayScale)") // Returning 1.0
}
}
}
Do I miss something with this environment guy? Muchos thankos.