Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS set UILabel value

Tags:

objective-c

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];
like image 603
NeilMortonNet Avatar asked Jun 25 '26 11:06

NeilMortonNet


2 Answers

self.myLabel.text = [NSString stringWithFormat:@"%d completed", numberValue];
like image 147
TotoroTotoro Avatar answered Jun 28 '26 06:06

TotoroTotoro


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.

like image 24
Erik Avatar answered Jun 28 '26 05:06

Erik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!