首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSMutableParagraphStyle和NSAttributedString失败了

NSMutableParagraphStyle和NSAttributedString失败了
EN

Stack Overflow用户
提问于 2014-02-23 00:40:28
回答 1查看 289关注 0票数 1

我正在尝试一个多行NSAttributedString,行距为1.25。

代码语言:javascript
复制
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];

这样就可以生成一行,而换行是无效的。

我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-23 00:50:04

代码语言:javascript
复制
[bodyFormat setLineSpacing:5];

破坏了这种行为。

还设置

代码语言:javascript
复制
description.numberOfLines = 0;

帮助..。(描述是UILabel)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21962650

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档