开发者

Cocoa Touch UITextField first character uppercase

开发者 https://www.devze.com 2022-12-18 22:56 出处:网络
I have a UITextField. How can I make sure that the first character is uppercase? I tried this. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementStri

I have a UITextField. How can I make sure that the first character is uppercase?

I tried this.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSUInteger newLength = [textField.text length] + [string length] - range.length;
if (newLength == 1) {
    string = [string uppercaseString];
}

return YES;

}

But even after uppercasing the string, it is still lower case开发者_运维技巧.

Thanks, Tee


Ah I got it. There is the capitalize option in Interface Builder.

Thanks, Tee

0

精彩评论

暂无评论...
验证码 换一张
取 消