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!
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!
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];
label.text = [NSString stringWithFormat:@"%i",intNumber];
NSNumber *number = [NSNumber numberWithInt:yourInt];
[yourLabel setText:[number stringValue]];
Hãy thử cách này:
[label setText:[NSString stringWithFormat:@"%d", intValue]];