2012-03-14 54 views
6

這個問題很自我解釋。我需要將UILabel實例的text屬性設置爲int。我如何去做這件事?對不起,如果這是一個沒有問題的問題。將UILabel的文本設置爲int?

謝謝!

回答

12

假設你有:

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

你能做到這一點,這是很簡單的:

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

或:

myLabel.text = [NSString stringWithFormat:@"%d", myInt]; 
2
label.text = [NSString stringWithFormat:@"%i",intNumber]; 
3
NSNumber *number = [NSNumber numberWithInt:yourInt]; 
[yourLabel setText:[number stringValue]]; 
0

試試這個:

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