NeilMortonNet
NeilMortonNet

Reputation: 1530

iOS set UILabel value

I would like to append the word "Completed" to the end of the self.myLabel.text, following the value returned from numberValue.

So, say numberValue returns 234, I would like self.myLabel.text to become "234 completed".

I am sure this is a simple task, but am missing the obvious?!

The code used to display the number only is:-

self.myLabel.text = [NSString stringWithFormat:@"%ld", numberValue];

Upvotes: 3

Views: 5487

Answers (4)

John
John

Reputation: 2480

As their is a first result in google and has not been updated for swift:

Swift:

var the_label
the_label.text = "the text to assign"

Upvotes: 0

Deepak Bharati
Deepak Bharati

Reputation: 280

if numberValue is integer use the following:

self.myLabel.text = [NSString stringWithFormat:@"%d completed", numberValue];

if numberValue is of type NSNumber or some unknown type just use as follow:

self.myLabel.text = [NSString stringWithFormat:@"%@ completed", numberValue];

Upvotes: 0

Erik
Erik

Reputation: 12868

If you are using NSNumber (or any similar object class such as NSString, NSDecimalNumber, NSDate), use the %@ format string.

So for your example: [NSString stringWithFormat:@"%@ completed", numberValue];

If you are using NSInteger, you can use the %d/%ld (long integer) formats.

Upvotes: 1

TotoroTotoro
TotoroTotoro

Reputation: 17622

self.myLabel.text = [NSString stringWithFormat:@"%d completed", numberValue];

Upvotes: 2

Related Questions