+ (void)disableAutoCorrectionsForTextfieldsAndTextViewGlobally { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ struct objc_method_description autocorrectionTypeMethodDescription = protocol_getMethodDescription(@protocol(UITextInputTraits), @selector(autocorrectionType), NO, YES); IMP noAutocorrectionTypeIMP_TEXT_FIELD = imp_implementationWithBlock(^(UITextField *_self) { return UITextAutocorrectionTypeNo; }); IMP noAutocorrectionTypeIMP_TEXT_VIEW = imp_implementationWithBlock(^(UITextView *_self) { return UITextAutocorrectionTypeNo; }); class_replaceMethod([UITextField class], @selector(autocorrectionType), noAutocorrectionTypeIMP_TEXT_FIELD, autocorrectionTypeMethodDescription.types); class_replaceMethod([UITextView class], @selector(autocorrectionType), noAutocorrectionTypeIMP_TEXT_VIEW, autocorrectionTypeMethodDescription.types); }); }
Alok Singh Sep 10 '15 at 7:14 2015-09-10 07:14
source share