iPhone:禁用UITextField上的自动上限/自动更正

由于某些原因,即使我禁用自动上限和自动更正我的UITextField,它仍然大写input的第一个字母。

这里是代码:

UITextField* textField = [[[UITextField alloc] initWithFrame:CGRectMake(90.0, 10.0, 213.0, 25.0)] autorelease]; [textField setClearButtonMode:UITextFieldViewModeWhileEditing]; textField.returnKeyType = UIReturnKeyGo; textField.autocorrectionType = FALSE; textField.autocapitalizationType = UITextAutocapitalizationTypeNone; textField.delegate = self; if (inputFieldType == Email) { label.text = @"Email:"; textField.keyboardType = UIKeyboardTypeEmailAddress; emailTextField = textField; textField.placeholder = @"Email Address"; } else { // password textField.secureTextEntry = TRUE; label.text = @"Password:"; if (inputFieldType == Password){ textField.placeholder = @"Password"; passwordTextField = textField; } if (inputFieldType == ConfirmPassword){ textField.placeholder = @"Confirm Password"; confirmPasswordTextField = textField; } } 

见截图: 替代文字http://grab.by/39WE

您将autocorrectionType设置为FALSE ,就像它是BOOL ,但实际上它的types是UITextAutocorrectionType 。 所以FALSE被解释为UITextAutocorrectionTypeDefault ,这意味着自动UITextAutocorrectionTypeDefault可能被启用。

我敢打赌,它在你的地址簿中find了“Phil”的名字,并且正在自动匹配大写字母。

目标 – C

 -(void)textFieldDidBeginEditing:(UITextField *)textField { textField.autocorrectionType = FALSE; // or use UITextAutocorrectionTypeNo textField.autocapitalizationType = UITextAutocapitalizationTypeNone; } 

迅速

 func textFieldDidBeginEditing(textfield : UITextField) { textField.autocorrectionType = .No textField.autocapitalizationType = .None textField.spellCheckingType = .No } 

Swift3

  func textFieldDidBeginEditing(_ textField : UITextField) { textField.autocorrectionType = .no textField.autocapitalizationType = .none textField.spellCheckingType = .no } 
 yourTextFieldName.autocorrectionType = UITextAutocorrectionTypeNo; yourTextFieldName.autocapitalizationType = UITextAutocapitalizationTypeNone; 

Swift 2:

 textField.autocorrectionType = .No textField.autocapitalizationType = .None