UITextField auto-capitalization type - iPhone App

后端 未结 7 1566
故里飘歌
故里飘歌 2021-01-30 15:29

Is there a way to set the autocapitalizationType for a UITextField so that the first letter of each word is capitalized by default?

This Is A

相关标签:
7条回答
  • 2021-01-30 15:50

    Yes. On InterfaceBuilder, on the textField attribute inspector, you can set up the Capitalization property to Words.

    0 讨论(0)
  • 2021-01-30 15:53

    There is an answer for Obj-C, im here for Swift;

    textField.autocapitalizationType = UITextAutocapitalizationType.words
    

    or shorter way

    textField.autocapitalizationType = .words
    
    0 讨论(0)
  • 2021-01-30 16:00

    Use textField.autocapitalizationType = UITextAutocapitalizationTypeWords;

    For more information please read: UITextInputTraits Protocol Reference

    0 讨论(0)
  • 2021-01-30 16:05

    You can even do that form the Storyboard or .xib file. Just have to select the textfield and in the attribute inspector on the right there is a Capitalization section where you can pick whatever suits you. In your case it's capitalisation "Words".

    0 讨论(0)
  • 2021-01-30 16:10

    Setting the capitalization property to "Words" will suggest that the user enter capitalized words. This can be overridden by the user by un-shifting on the keyboard. The best thing to do is capitalize the words in code:

    NSString *text = [myTextField.text capitalizedString];
    
    0 讨论(0)
  • 2021-01-30 16:13

    In Xamarin.ios / Monotouch this worked for me:

    textField.AutocapitalizationType = UITextAutocapitalizationType.Words;
    
    0 讨论(0)
提交回复
热议问题