Skip to content

Instantly share code, notes, and snippets.

@stefanceriu
Last active January 17, 2022 15:10
Show Gist options
  • Save stefanceriu/3c21452b7d481ceae41c0ca5f0f5c15d to your computer and use it in GitHub Desktop.
Save stefanceriu/3c21452b7d481ceae41c0ca5f0f5c15d to your computer and use it in GitHub Desktop.
Disable Mac Catalyst 77% app scaling
//
// UINSSceneView+CTX.h
// EFClass
//
// Created by Stefan Ceriu on 28/11/2019.
// Copyright © 2019 EF Education First. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSObject (CTX)
@end
//
// UINSSceneView+CTX.m
// EFClass
//
// Created by Stefan Ceriu on 28/11/2019.
// Copyright © 2019 EF Education First. All rights reserved.
//
#import "UINSSceneView+CTX.h"
#import <objc/runtime.h>
@implementation NSObject (CTX)
+ (void)load
{
#if TARGET_OS_MACCATALYST
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
CTXSwizzleInstanceMethod(objc_getClass("UINSSceneView"), NSSelectorFromString(@"scaleFactor"), @selector(ctx_scaleFactor));
});
#endif
}
- (CGFloat)ctx_scaleFactor
{
return 1.0f;
}
static void CTXSwizzleInstanceMethod(Class class, SEL originalSelector, SEL swizzledSelector) {
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
if (class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))) {
class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}
@end
@Neil20170220
Copy link

not work on macOS 11.3

@JunyuKuang
Copy link

macOS 11.3 has different APIs. I have made my implementation public: OverrideCatalystScaleFactor.swift

@stefanceriu
Copy link
Author

Nice! 👌

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