Skip to content

Instantly share code, notes, and snippets.

@mhdhejazi
Created April 27, 2020 10:42
Show Gist options
  • Save mhdhejazi/bbf5c209fa8ff9dc50be2a7c7809d7c4 to your computer and use it in GitHub Desktop.
Save mhdhejazi/bbf5c209fa8ff9dc50be2a7c7809d7c4 to your computer and use it in GitHub Desktop.
Change the window scale factor in a Mac Catalyst app with the help of Dynamic (https://github.com/mhdhejazi/Dynamic)
override func viewDidAppear(_ animated: Bool) {
view.window?.scaleFactor = 1.0 // Default value is 0.77
}
extension UIWindow {
var scaleFactor: CGFloat {
get {
Dynamic.NSApplication.sharedApplication
.windows.firstObject.contentView
.subviews.firstObject.scaleFactor ?? 1.0
}
set {
Dynamic.NSApplication.sharedApplication
.windows.firstObject.contentView
.subviews.firstObject.scaleFactor = newValue
}
}
}
@mhdhejazi
Copy link
Author

A safer way for finding the scene view would be:

let contentView = Dynamic.NSApplication.sharedApplication.windows.firstObject.contentView
let sceneView = sceneView.subviews.asArray?.first {
    String(describing: type(of: $0)) == "UINSSceneView"
}
Dynamic(sceneView).scaleFactor = 1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment