I want to disable Autocorrection on all textfields in my application. I'm aware of the autocorrectionType
property on UITextField. However, I didn't subclass UITextField when I started to develop my application. So I'm looking for a solution to disable autocorrect on all my TextField with a single line of code.
I tried using [UITextField appearance]
, which works for the keyboard appearance:
[[UITextField appearance] setKeyboardAppearance:UIKeyboardAppearanceDark];
But not for autocorrection, since the following line of code:
[[UITextField appearance] setAutocorrectionType:UITextAutocorrectionTypeNo];
Results in a inconsistency exception:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Please file a radar on UIKit if you see this assertion.'
I would suggest to go with sub-classing 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 in all over your project (either in code or in storyboard).
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With