Fitzy
Fitzy

Reputation: 1889

Setting the text of a UILabel to an int?

The question is pretty much self explanatory. I need to set the text property of a UILabel instance to an int. How do I go about doing this? Sorry if it's a nooby question.

Thanks!

Upvotes: 7

Views: 11787

Answers (4)

Anooj VM
Anooj VM

Reputation: 2633

Try this:

 [label setText:[NSString stringWithFormat:@"%d", intValue]];

Upvotes: 0

Assuming you have:

UILabel *myLabel; //instance of your label
int myInt; //the integer you need to set as text into UILabel

you can do this, and it's pretty simple:

[myLabel setText:[NSString stringWithFormat:@"%d", myInt]];

or:

myLabel.text = [NSString stringWithFormat:@"%d", myInt];

Upvotes: 14

janusfidel
janusfidel

Reputation: 8106

NSNumber *number = [NSNumber numberWithInt:yourInt];
[yourLabel setText:[number stringValue]];

Upvotes: 3

Krrish
Krrish

Reputation: 2256

label.text = [NSString stringWithFormat:@"%i",intNumber];

Upvotes: 2

Related Questions