0

New to the site. Not able to solve my problem from other posts. Seems simple enough, but I'm obviously missing something. I'm working in Xcode and have an array of float numbers. I want to output all to a label in vertical format. When I run the following code, I get a return of the last number only.

for (int x = 0; x < 6; ++x)
       [myLabel setText:[NSString stringWithFormat:@"%f\n", numberArray[x]]];

What code needs to be added for all values to display? Reviewed a couple of other posts with similar question, but the solutions seemed overly complex for the issue and didn't work for me. Appreciate any guidance.

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
radams
  • 13
  • 3
  • try to set the `UILabel`'s numberOfLines to 0. – MaappeaL Dec 04 '14 at 06:55
  • possible duplicate of [Appending NSAttributedString with line break returns attributed string with wrong format](http://stackoverflow.com/questions/22681008/appending-nsattributedstring-with-line-break-returns-attributed-string-with-wron) – Hussain Shabbir Dec 04 '14 at 07:29

2 Answers2

3

Try:

NSMutableString *myLabelText = [[NSMutableString alloc] init];
for (int x = 0; x < 6; ++x) {
    [myLabelText appendFormat:@"%f\n", numberArray[x]];
}
[myLabel setText:myLabelText];
pshah
  • 2,052
  • 1
  • 21
  • 40
0

Try this one :

myLabel.numberOfLines = 0;
myLabel.lineBreakMode = NSLineBreakByWordWrapping;
[myLabel setText:[numberArray componentsJoinedByString:@"\n"]];
[myLabel sizeToFit];
Hemant Chittora
  • 3,152
  • 3
  • 19
  • 25