I would like to disable text-entry autocorrect in an iPad application, regardless of what the global settings for autocorrect are on the device. Is there a good way to do this t
Im sorry but you have to go trough all the text fields and disable it
You can probably subclass UITextField and set your desired properties to it. Instead of the UITextField you can use this subclassed version.
This may be worthy if you haven't started implementing your application yet!
as @cocoakomali
suggested, you can create a category of UITextField
to disable autocorrect for all UITextField
in the app by default
@implementation UITextField (DisableAutoCorrect)
- (instancetype)init {
self = [super init];
if (self) {
[self setAutocorrectionType:UITextAutocorrectionTypeNo];
}
return self;
}
@end
You can override the default text field autocorrection type with a bit of method swizzling. In your app delegate or somewhere else sensible:
#import <objc/runtime.h>
// Prevent this code from being called multiple times
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
struct objc_method_description autocorrectionTypeMethodDescription = protocol_getMethodDescription(@protocol(UITextInputTraits), @selector(autocorrectionType), NO, YES);
// (Re)implement `-[UITextField autocorrectionType]` to return `UITextAutocorrectionTypeNO`.
IMP noAutocorrectionTypeIMP = imp_implementationWithBlock(^(UITextField *_self){ return UITextAutocorrectionTypeNo; });
class_replaceMethod([UITextField class], @selector(autocorrectionType), noAutocorrectionTypeIMP, autocorrectionTypeMethodDescription.types);
});