开发者

iphone : How to capitalize the first character of my textfield?

开发者 https://www.devze.com 2023-03-06 19:31 出处:网络
In my iPhone app, I want to capitalize the first chara开发者_如何学Pythoncter in my UITextField\'s text.

In my iPhone app, I want to capitalize the first chara开发者_如何学Pythoncter in my UITextField's text.

How can it be done?


Simple:

NSString *text = [textField text];
NSString *capitalized = [[[text substringToIndex:1] uppercaseString] stringByAppendingString:[text substringFromIndex:1]];

NSLog(@"%@ uppercased is %@", text, capitalized); 


In Interface Builder (or IB integrated into Xcode 4), if you click on UITextField you can set the text and keyboard behaviour.

iphone : How to capitalize the first character of my textfield?


NSString *capitalizedString = [textField.text capitalizedString];


here I'm giving a suggestion you try with is . I hope it will be helpful for you.

Go in xib, select textfield then in attribute inspector you got capitalization just select words option


If you have set up the text field in a nib file, select the nib you will see various 'Text Input Traits' in the Text Field Attributes - the first one in the list deals with capitalisation.

see rjstelling's answer.....


Set the Capitalization drop down under textfield attributes to Sentences.


Instead of tanking it separate and capitalizing, try this. Simple 1 line code.

NSString *text = [textField text];
NSString *capText = [text capitalizedString]; // capitalizes only first alphabet.
0

精彩评论

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