Skip to content

Instantly share code, notes, and snippets.

@stefanceriu
Last active February 4, 2020 13:28
Show Gist options
  • Save stefanceriu/0fedb537c69444e2b85cbafc663e9cac to your computer and use it in GitHub Desktop.
Save stefanceriu/0fedb537c69444e2b85cbafc663e9cac to your computer and use it in GitHub Desktop.
Remove default Mac Catalyst application text view focus rings
//
// UITextView+CTX.h
// EFClass
//
// Created by Stefan Ceriu on 27/11/2019.
// Copyright © 2019 EF Education First. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UITextView (CTX)
@end
//
// UITextView+CTX.m
// EFClass
//
// Created by Stefan Ceriu on 27/11/2019.
// Copyright © 2019 EF Education First. All rights reserved.
//
#import "UITextView+CTX.h"
#import <objc/runtime.h>
@implementation UITextView (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