Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 具有不同NSMutableParagraphStyle的NSAttribute字符串_Ios_Attributes_Nsattributedstring - Fatal编程技术网

Ios 具有不同NSMutableParagraphStyle的NSAttribute字符串

Ios 具有不同NSMutableParagraphStyle的NSAttribute字符串,ios,attributes,nsattributedstring,Ios,Attributes,Nsattributedstring,我有1个带多段落的属性字符串。 我已经给出了FirstLineHeadIndent=2.12。 现在我想给第一段加上FirstLineHeadIndent=0 和FirstLineHeadIndent=2到属性字符串中的第二段 如果我将属性设置为 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineSpacing =Line_sp

我有1个带多段落的属性字符串。
我已经给出了
FirstLineHeadIndent=2.12。

现在我想给第一段加上
FirstLineHeadIndent=0
FirstLineHeadIndent=2
到属性字符串中的第二段

如果我将属性设置为

 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,
                              };
这将给两位巴拉圭人提供头部空间。 请帮帮我。
我正在上传图片以获取更多帮助:-

因此,解决方案是使用两种段落样式。
您的
NSString
由一个
\n
分隔,表示两段之间的分隔

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

你是如何将段落样式设置为你的
NSAttributedString
?@Larme我已经用NSMutableParagraphStyle设置了段落样式。但是它给了所有段落以imapact。我想将不同的样式设置为第一段和第二段。例如1)段落的行间距为2,第二段的行间距为4。你能显示所有的段落吗代码?NSMutableParagraphStyle*paragraphStyle=[[NSMutableParagraphStyle alloc]init];paragraphStyle.firstLineHeadIndent=2;段落样式。段落间距=段落间距;NSDictionary*ats=@{NSFontAttributeName:[UIFontWithName:self.bookView.defaultFontFamily size:self.bookView.defaultFontSize],NSParagraphStyleAttributeName:paragraphStyle,};您需要使用两段式,范围不同。你就是这么做的吗?