2010-03-19 49 views
46

由於某些原因,即使我禁用自動上限和自動更正我的UITextField,它仍然會大寫輸入的第一個字母。iPhone:禁用UITextField上的自動上限/自動更正

下面是代碼:

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; 
    } 

} 

見截圖: alt text http://grab.by/39WE

回答

60

你設置autocorrectionTypeFALSE就好像它是一個BOOL,但它實際上具有類型UITextAutocorrectionType。因此FALSE被解釋爲UITextAutocorrectionTypeDefault,這意味着可能啓用了自動更正。

我敢打賭,它在你的通訊錄中找到了名字「Phil」,並且正在自動修改大小寫以匹配。

+1

哈!我有相反的問題。我正確禁用了自動更正 - 但將自動大寫設置爲FALSE - D哦! – philsquared 2011-10-21 20:54:06

30

的Objective - 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 
} 
+0

Hello Anbu,我們如何爲NSTextfield(Mac app)啓用相同的選項(textField.autocorrectionType = FALSE; //或使用UITextAutocorrectionTypeNo)。有什麼想法嗎? – Surezz 2016-12-15 07:16:48

7
yourTextFieldName.autocorrectionType = UITextAutocorrectionTypeNo; 
yourTextFieldName.autocapitalizationType = UITextAutocapitalizationTypeNone; 
2

Swift 2:

textField.autocorrectionType = .No 
textField.autocapitalizationType = .None 
+1

請添加您提出的解決方案的說明。 – 2015-12-16 18:44:23