Question

I am attempting to have a multiline NSAttributedString, with a line spacing of 1.25.

NSMutableParagraphStyle *bodyFormat = [[NSMutableParagraphStyle alloc] init];
bodyFormat.alignment = NSTextAlignmentLeft;
//[bodyFormat setLineSpacing:5];
[bodyFormat setLineBreakMode:NSLineBreakByWordWrapping];
//[bodyFormat setMaximumLineHeight:5];
[bodyFormat setLineHeightMultiple:1.25];





NSMutableAttributedString *desc = [[NSMutableAttributedString alloc] initWithString:@"So why to use Lorem Ipsum and why placeholder text is necessary? Naturally, page designs that are made for text documents must contain some text rather than placeholder dots or something else. Howevr, should they contain a proper English words and sentenses almost every reader will deliberately try to interpret it eventually missing the design itself"];
[desc addAttribute:NSParagraphStyleAttributeName value:bodyFormat range:NSMakeRange(0, desc.length)];





UILabel *description = [[UILabel alloc] initWithFrame:CGRectMake(0,
                                                                 20,
                                                                 300,
                                                                 1000)];

description.lineBreakMode = NSLineBreakByWordWrapping;
[description setAttributedText:desc];
[self.view addSubview:description];

This manages to produce a single line, and the linebreak is not effective.

What am I doing wrong?

Was it helpful?

Solution

[bodyFormat setLineSpacing:5];

breaks this behavior.

Also setting

description.numberOfLines = 0;

helps... (description is the UILabel)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top