将UILabel的文本设置为int?

Fit*_*tzy 7 int text objective-c nsstring uilabel

这个问题几乎是自我解释的.我需要将UILabel实例的text属性设置为int.我该怎么做呢?对不起,如果这是一个不起眼的问题.

谢谢!

Gio*_*lis 14

假设你有:

UILabel *myLabel; //instance of your label
int myInt; //the integer you need to set as text into UILabel
Run Code Online (Sandbox Code Playgroud)

你可以这样做,而且非常简单:

[myLabel setText:[NSString stringWithFormat:@"%d", myInt]];
Run Code Online (Sandbox Code Playgroud)

要么:

myLabel.text = [NSString stringWithFormat:@"%d", myInt];
Run Code Online (Sandbox Code Playgroud)