我正在尝试使用多行NSAttributedString,行间距为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];
这会产生一条线,并且换行无效。
我做错了什么?
答案 0 :(得分:1)
[bodyFormat setLineSpacing:5];
打破了这种行为。
同时设置
description.numberOfLines = 0;
帮助...(描述是UILabel)