iOS设置UILabel值

时间:2013-12-16 21:52:44

标签: objective-c

我想在number.Value返回的值之后,在self.myLabel.text的末尾附加单词“Completed”。

所以,假设numberValue返回234,我希望self.myLabel.text成为“234完成”。

我确信这是一项简单的任务,但我错过了显而易见的事情?!

用于显示数字的代码是: -

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

4 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

如果您使用NSNumber(或任何类似的对象类,例如NSStringNSDecimalNumberNSDate),请使用%@格式字符串。< / p>

因此,对于您的示例:[NSString stringWithFormat:@"%@ completed", numberValue];

如果您使用NSInteger,则可以使用%d / %ld(长整数)格式。

答案 2 :(得分:0)

如果numberValue是整数,请使用以下内容:

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

如果numberValue属于NSNumber类型或某种未知类型,请按以下方式使用:

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

答案 3 :(得分:0)

因为他们是谷歌的第一个结果,并且尚未针对swift进行更新:

夫特:

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