54

For some reason, even though I disable the auto-cap and auto-correct of my UITextField, it's still capitalizing the first letter of my input.

Here is the code:

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

}

See screenshot: alt text http://grab.by/39WE

Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
phil swenson
  • 8,564
  • 20
  • 74
  • 99

6 Answers6

69

You're setting autocorrectionType to FALSE as if it were a BOOL, but it actually has type UITextAutocorrectionType. So FALSE is being interpreted as UITextAutocorrectionTypeDefault, which means that autocorrection is probably enabled.

I bet it found the name "Phil" in your address book and is autocorrecting the capitalization to match.

Tom
  • 3,831
  • 1
  • 22
  • 24
  • 1
    Ha! I had the opposite problem. I had auto correction disabled correctly - but was setting auto capitalization to FALSE - d'oh! – philsquared Oct 21 '11 at 20:54
40

Objective - C

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

}

Swift

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
}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
  • Hello Anbu, How we can enable the same option ( textField.autocorrectionType = FALSE; // or use UITextAutocorrectionTypeNo) for NSTextfield (Mac app). Any thoughts? – Surezz Dec 15 '16 at 07:16
7
yourTextFieldName.autocorrectionType = UITextAutocorrectionTypeNo;
yourTextFieldName.autocapitalizationType = UITextAutocapitalizationTypeNone;
Subham93
  • 633
  • 8
  • 14
5

Updated the correct answer for Swift 5

    textField.autocorrectionType = .no
    textField.autocapitalizationType = .none
    textField.spellCheckingType = .no
Chris Peragine
  • 158
  • 2
  • 8
2

Swift 2:

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

If you wish to disable Auto-Cap/autocorrect on a UITextField for whole project,

then make a class which will inherit the UITextField class and init method set the autoCorrectionType to "no".

Class AppTextField: UITextField {

     override init(frame: CGRect) {
         super.init(frame: frame)

         //setting the autocorrection to no
          self.autocorrectionType = .no
      }
}

Then in storyboard set the cusotom class for textfield to AppTextField.

enter image description here

Vikash Sinha
  • 869
  • 1
  • 7
  • 21