Skip to content

Instantly share code, notes, and snippets.

@stefanceriu
Last active April 3, 2021 09:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanceriu/794d79f163abc4f5b40cc1fcd85d6736 to your computer and use it in GitHub Desktop.
Save stefanceriu/794d79f163abc4f5b40cc1fcd85d6736 to your computer and use it in GitHub Desktop.
Remove default Mac Catalyst application text field focus rings
//
// 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
//
// 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