如何在UIAlertView的UITextField上设置自动资产?

时间:2011-10-29 03:33:22

标签: iphone objective-c cocoa-touch uitextfield uialertview

有没有办法在新的UIAlertView上设置文字输入的自动大写选项?
我想以大写字母开头:

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Add Name" message:@"Enter name for routine" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];
    [alert setAlertViewStyle:UIAlertViewStylePlainTextInput];
    [alert show];

2 个答案:

答案 0 :(得分:40)

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Add Name" message:@"Enter name for routine" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];
[alert setAlertViewStyle:UIAlertViewStylePlainTextInput];
[alert textFieldAtIndex:0].autocapitalizationType = UITextAutocapitalizationTypeSentences;
[alert show];

答案 1 :(得分:2)

根据您的喜好有三种类型。

首先是将每个单词的第一个字母大写:

[alert textFieldAtIndex:0].autocapitalizationType = UITextAutocapitalizationTypeWords;

第二个是大写所有单词

[alert textFieldAtIndex:0].autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;

第三是将句子中的每个单词都大写

[alert textFieldAtIndex:0].autocapitalizationType = UITextAutocapitalizationTypeSentences;