Disable auto-correction for UITextField in the whole application

I want to disable Autocorrection for all text fields in my application. I know the autocorrectionType property on a UITextField. However, when I started developing the application, I did not subclass UITextField. So I'm looking for a solution to turn off auto-replace on my entire TextField with a single line of code.

I tried using [UITextField appearance] , which works for the appearance of the keyboard:

 [[UITextField appearance] setKeyboardAppearance:UIKeyboardAppearanceDark]; 

But not for auto-correction, as the following line of code:

 [[UITextField appearance] setAutocorrectionType:UITextAutocorrectionTypeNo]; 

Results in case of inconsistency:

  *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Please file a radar on UIKit if you see this assertion.' 
+6
source share
1 answer

I would suggest going with a subclass of UITextField :

 @interface CustomTextField : UITextField @end @implementation CustomTextField - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code [self setAutocorrectionType:UITextAutocorrectionTypeNo]; // same way add all the generalize properties which you require for all the textfields. } return self; } 

Now use CustomTextField throughout your project (either in code or in storyboard).

Hope this helps.

+1
source

All Articles