Ankit Chauhan
Ankit Chauhan

Reputation: 2405

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?

Upvotes: 4

Views: 13508

Answers (7)

user8065217
user8065217

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

Andrew Aquino
Andrew Aquino

Reputation: 42

Set the Capitalization drop down under textfield attributes to Sentences.

Upvotes: 0

Sandip Patel - SM
Sandip Patel - SM

Reputation: 3394

NSString *capitalizedString = [textField.text capitalizedString];

Upvotes: 4

Jacob Relkin
Jacob Relkin

Reputation: 163228

Simple:

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

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

Upvotes: 23

sandy_iphone
sandy_iphone

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

Damo
Damo

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

Richard Stelling
Richard Stelling

Reputation: 25665

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

Upvotes: 15

Related Questions