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.

2

2 Answers 2

3

Try:

NSMutableString *myLabelText = [[NSMutableString alloc] init];
for (int x = 0; x < 6; ++x) {
    [myLabelText appendFormat:@"%f\n", numberArray[x]];
}
[myLabel setText:myLabelText];
Sign up to request clarification or add additional context in comments.

1 Comment

Works perfectly. Clean and simple.
0

Try this one :

myLabel.numberOfLines = 0;
myLabel.lineBreakMode = NSLineBreakByWordWrapping;
[myLabel setText:[numberArray componentsJoinedByString:@"\n"]];
[myLabel sizeToFit];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.