首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不同NSMutableParagraphStyle的Nsattributedstring

不同NSMutableParagraphStyle的Nsattributedstring
EN

Stack Overflow用户
提问于 2014-05-14 09:15:52
回答 1查看 2.8K关注 0票数 4

我有一个带有多个段落的属性字符串。

我给了FirstLineHeadIndent = 2.12.

现在,我想在属性字符串中将FirstLineHeadIndent=0给第1段,FirstLineHeadIndent=2给出第2段。

如果我将属性设置为

代码语言:javascript
复制
 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing =Line_space;
        paragraphStyle.firstLineHeadIndent =2;
        paragraphStyle.headIndent =margin_space;
        paragraphStyle.tailIndent =-margin_space;
        paragraphStyle.paragraphSpacing=paragraph_space;

        NSDictionary *ats = @{
                              NSFontAttributeName : [UIFont fontWithName:self.bookView.defaultFontFamily size:self.bookView.defaultFontSize],
                              NSParagraphStyleAttributeName : paragraphStyle,
                              };

它将给双方的副翼头部空间。请帮帮我。我上传这张图片以寻求更多帮助:-

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-14 12:24:45

因此,解决方案是使用2段样式。

您的NSString由一个\n分隔,该\n表示两段之间的分隔。

代码语言:javascript
复制
NSMutableParagraphStyle *firstParagraphStyle = [[NSMutableParagraphStyle alloc] init];
[firstParagraphStyle setFirstLineHeadIndent:0];
//Do the rest of the settings

NSMutableParagraphStyle *secondParagraphStyle = [[NSMutableParagraphStyle alloc] init];
[secondParagraphStyle setFirstLineHeadIndent:2];
//Do the rest of the settings

//You may use the same paragraphStyle, changing just the firstLineHeadIndent, and set the attributes, but for a clearer explanation, I used 2 paragraph styles
NSRange range = [[yourAttributedString string] rangeOfString:@"\n"];

[yourAttributedString addAttribute:NSParagraphStyleAttributeName value: firstParagraphStyle range:NSMakeRange(0, range.location)]; //The range is from the start to the \n

[yourAttributedString addAttribute:NSParagraphStyleAttributeName value: secondParagraphStyle range:NSMakeRange(range.location, [[yourAttributedString string] length]-range.location)]; //The range is from the start of \n to the end
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23650373

复制
相关文章

相似问题

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