你不提這SDK,您正在使用,但對3.0及以上我看到你想要的行爲。
這就是說,你總是可以在文本更改爲大寫,當他們使用完畢textFieldDidEndEditing方法從委託編輯:
- (void)textFieldDidEndEditing:(UITextField *)textField {
NSString *textToUpper = [textField.text uppercaseString];
[theTextField setText:textToUpper];
}
或者,通過對文本字段設置的通知時,它改變,因爲它是被類型化,你可以改變文本:
// setup the UITextField
{
theTextField.delegate = self;
theTextField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
[theTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
}
你必須這樣做,因爲這樣一來,不像的UISearchBar,UITextField不執行textDidChange。也許這樣的事情?
- (void)textFieldDidChange:(UITextField *)textField {
NSRange range = [textField.text rangeOfString : @"-"];
if (range.location != NSNotFound) {
theTextField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
}
}
來源
2010-09-04 14:14:54
hjd