2012-03-14 33 views
6

Câu hỏi khá tự giải thích. Tôi cần thiết lập thuộc tính văn bản của một cá thể UILabel thành một int. Làm thế nào để tôi làm việc này? Xin lỗi nếu đó là một câu hỏi nooby.Đặt văn bản của UILabel thành int?

Cảm ơn!

Trả lời

12

Giả sử bạn có:

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

bạn có thể làm điều này, và nó khá đơn giản:

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

hay:

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

Hãy thử cách này:

[label setText:[NSString stringWithFormat:@"%d", intValue]]; 
Các vấn đề liên quan