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
How to make the text of UITextField to appear with First letter Capital in iPhone
提问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 Capitalization
with a drop down menu. Here, you can select Words
, Sentences
, or All Characters
.
在Attributes Inspector 中,靠近 Text Field 部分底部的地方,有一个名为Capitalization
下拉菜单的设置。在这里,你可以选择Words
,Sentences
或All Characters
。
回答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!!!