Last active
April 3, 2021 09:23
-
-
Save stefanceriu/794d79f163abc4f5b40cc1fcd85d6736 to your computer and use it in GitHub Desktop.
Remove default Mac Catalyst application text field focus rings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UITextField+CTX.h | |
// EFClass | |
// | |
// Created by Stefan Ceriu on 27/11/2019. | |
// Copyright © 2019 EF Education First. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UITextField (CTX) | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UITextField+CTX.m | |
// EFClass | |
// | |
// Created by Stefan Ceriu on 27/11/2019. | |
// Copyright © 2019 EF Education First. All rights reserved. | |
// | |
#import "UITextField+CTX.h" | |
#import <objc/runtime.h> | |
@implementation UITextField (CTX) | |
+ (void)load | |
{ | |
#if TARGET_OS_MACCATALYST | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
CTXSwizzleInstanceMethod([self class], NSSelectorFromString(@"_focusRingType"), @selector(ctx_focusRingType)); | |
}); | |
#endif | |
} | |
- (NSUInteger)ctx_focusRingType | |
{ | |
return 1; // NSFocusRingTypeNone | |
} | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment