ios 如何使 UITextField 的文本在 iPhone 中显示为首字母大写

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1180793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 16:12:38  来源:igfitidea点击:

How to make the text of UITextField to appear with First letter Capital in iPhone

iosiphoneuitextfield

提问by rkb

I have a text box and I am only interested in capitalizing the first letter, So how to do that in iPhone UITextField.

我有一个文本框,我只对大写第一个字母感兴趣,那么如何在 iPhone UITextField 中做到这一点。

回答by ennuikiller

try this:

尝试这个:

tf = [[UITextField alloc] init];
tf.autocapitalizationType = UITextAutocapitalizationTypeSentences;

or set this property in the properties inspector in Interface Builder

或在 Interface Builder 的属性检查器中设置此属性

回答by Ketan P

Swift 3 :

斯威夫特3:

textField.autocapitalizationType = .sentences
textField.autocapitalizationType = .words
textField.autocapitalizationType = .allCharacters

Output :

输出 :

  • Sentences: This is text input.
  • Words: This Is Text Input.
  • All characters: THIS IS TEXT INPUT.
  • 句子:这是文本输入。
  • 文字:这是文本输入。
  • 所有字符:这是文本输入。

回答by jungledev

In the Attributes Inspector, near the bottom of the Text Field section, there is a setting called Capitalizationwith a drop down menu. Here, you can select Words, Sentences, or All Characters.

Attributes Inspector 中,靠近 Text Field 部分底部的地方,有一个名为Capitalization下拉菜单的设置。在这里,你可以选择WordsSentencesAll Characters

enter image description here

在此处输入图片说明

回答by Nipul Daki

In the Attributes Inspector , there is a Capitalization with a drop down menu. Here, you can select Words, Sentences, or All Characters.

在 Attributes Inspector 中,有一个带有下拉菜单的大写。在这里,您可以选择单词、句子或所有字符。

  • Word: if you select Word than first character of every word is Capital
  • Sentences: if you Sentence than first character of First word of every sentence is Capital
  • All Characters: All Characters are Capital
  • Word:如果您选择 Word 则每个单词的第一个字符是大写
  • 句子:如果你的句子比每个句子第一个单词的第一个字符是大写
  • 所有字符:所有字符都是大写

回答by Mike.R

Swift:

迅速:

tf.autocapitalizationType = .sentences

回答by M.Hamza

Select your text field ,go in interface builder(properties option) storyboard there is a option Capatalization set it to sentence.enjoy!!!

选择您的文本字段,进入界面构建器(属性选项)故事板有一个选项 Capatalization 将其设置为 sentence.enjoy!!!