Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In my iPhone app, I want to capitalize the first character in my UITextField's text.

How can it be done?

like image 823
Ankit Chauhan Avatar asked Nov 26 '22 22:11

Ankit Chauhan


2 Answers

Simple:

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

NSLog(@"%@ uppercased is %@", text, capitalized); 
like image 140
Jacob Relkin Avatar answered Dec 21 '22 05:12

Jacob Relkin


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

Xcode 4 IB

like image 38
Richard Stelling Avatar answered Dec 21 '22 07:12

Richard Stelling