2011-04-26 118 views

回答

34

使用autocapitalizationType爲UITextField的大寫字母。

txtfield1.autocapitalizationType = UITextAutocapitalizationTypeWords; 
+6

如果模擬器或「自動大寫」從「設置」>「常規」>「鍵盤」>「 iOS/iDevice上的大小寫 – NaXir 2013-06-13 08:14:41

+0

請注意,如果對文本字段禁用了自動更正,則此解決方案不起作用。 – alexey 2014-04-17 09:12:17

+0

如果你想使第一個字母大寫,你應該使用UITextAutocapitalizationTypeSentences。因爲UITextAutocapitalizationTypeWords會將文本字段中每個單詞的首字母大寫,而不僅僅是第一個字母。 – Werewolf 2016-04-08 08:19:22

4
txtfield1.autocapitalizationType = UITextAutocapitalizationTypeWords; 

,或者您也可以嘗試

[addrecipe.txtfdName setText:[txtfield1.text capitalizedString]]; // the first character from each word in the receiver changed to its corresponding uppercase value 
14

使用此代碼,以資本第一後

NSString *abc = @"this is test"; 

abc = [NSString stringWithFormat:@"%@%@",[[abc substringToIndex:1] uppercaseString],[abc substringFromIndex:1] ];  
NSLog(@"abc = %@",abc); 
8

符合要手動爲每個字的第一個字母代碼:

NSString* name = [addrecipe.txtfdName setText:txtfield1.text]; 
name = [name capitalizedString]; 
1

選擇txtfield1和去屬性檢查器,有一個下拉菜單的大寫字母和選擇菜單形式關注

:如果您選擇Word不是每個單詞的第一個字符是資本

:如果句子不是每一句的第一個字的第一個字符是資本

所有字符 :所有角色都是首都

相關問題