Reputation: 2405
In my iPhone app, I want to capitalize the first character in my UITextField's text.
How can it be done?
Upvotes: 4
Views: 13508
Reputation:
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.
Upvotes: 0
Reputation: 42
Set the Capitalization drop down under textfield attributes to Sentences.
Upvotes: 0
Reputation: 3394
NSString *capitalizedString = [textField.text capitalizedString];
Upvotes: 4
Reputation: 163228
Simple:
NSString *text = [textField text];
NSString *capitalized = [[[text substringToIndex:1] uppercaseString] stringByAppendingString:[text substringFromIndex:1]];
NSLog(@"%@ uppercased is %@", text, capitalized);
Upvotes: 23
Reputation: 39
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
Upvotes: 1
Reputation: 12890
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.....
Upvotes: 0
Reputation: 25665
In Interface Builder (or IB integrated into Xcode 4), if you click on UITextField you can set the text and keyboard behaviour.
Upvotes: 15