0
NSArray *myArray = @[@"1st:array1", 
                     @"2nd:array2", 
                     @"3rd:array3"
                    ];
NSString *labelString = [myArray componentsJoinedByString:@"\n"];

In this codelabelStringcan be word wrapped.
But if use NSMutableAttributedString like this

NSAttributedString *resultString = [resultArray componentsJoinedByString:@"\n"];

it can't be joined by @"\n". Any other method is existed? Thanks.

Penguin
  • 863
  • 1
  • 9
  • 22
  • 1
    http://stackoverflow.com/questions/23469509/display-edited-nsstring-in-order/23469708#23469708 – Larme Sep 28 '14 at 13:43
  • @Larme Hm,, it's little hard to understand it, but I'll try it. Thanks. – Penguin Sep 28 '14 at 13:52
  • It's not that hard. You just have to understand the algorithm/logic behind `componentsJoinedByString:`, and adapt it to your needs. – Larme Sep 28 '14 at 13:54

1 Answers1

-2

It's not difficult. You just know one thing.
AttributedString can't have \n maybe. So you just put \n in NSString.
And just make NSAttributedString from this NSString.
Here this code. I hope this code help your work.

NSString *commentString;    
NSMutableArray *resultArray = [[NSMutableArray alloc]initWithCapacity:50];    

for (InstagramComment *comment in comments) {
    commentString = [NSString stringWithFormat:@"%@:%@\n", comment.user.username, comment.text];

    NSMutableAttributedString *styledCommentString = [[NSMutableAttributedString alloc]initWithString:commentString];
    [resultArray addObject:styledCommentString];
}

NSMutableAttributedString *resultString = [[NSMutableAttributedString alloc]init];

for (int i = 0; i < resultArray.count; ++i) {
    [resultString appendAttributedString:[resultArray objectAtIndex:i]];
} [cell.comment setAttributedText:resultString];
Penguin
  • 863
  • 1
  • 9
  • 22