我想在我的应用程序中的所有文本字段上禁用自动更正。我知道 UITextField 上的 autocorrectionType
属性。但是,当我开始开发我的应用程序时,我没有将 UITextField 子类化。因此,我正在寻找一种解决方案,通过一行代码在我的所有 TextField 上禁用自动更正。
我尝试使用 [UITextField appearance]
,它适用于键盘外观:
[[UITextField appearance] setKeyboardAppearance:UIKeyboardAppearanceDark];
但不适用于自动更正,因为以下代码行:
[[UITextField appearance] setAutocorrectionType:UITextAutocorrectionTypeNo];
导致不一致异常:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Please file a radar on UIKit if you see this assertion.'
最佳答案
我建议对 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;
}
现在在整个项目中使用 CustomTextField(在代码中或 Storyboard中)。
希望这对您有所帮助。
关于ios - 在整个应用程序中禁用 UITextField 的自动更正,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34154257/