2014-05-14 3 views
2

여러 단락과 함께 1 개의 귀속 문자열이 있습니다.
는 I는 FirstLineHeadIndent = 2.12.
지금 나는 기인 문자열에서 두 번째 단락에 1 단락 및 FirstLineHeadIndent=2FirstLineHeadIndent=0을주고 싶다 부여했다.다른 NSMutableParagraphStyle을 가진 Nsattributedstring

내가

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, 
           }; 

같은 속성을 설정하면 그것은 모두 paragaraph에 머리 공간을 제공 할 것입니다. 도와주세요. 더 많은 도움을 받으려면 다음 이미지를 업로드하고 있습니다. - enter image description here

+1

어떻게 'NSAttributedString'에 단락 스타일을 설정 했습니까? – Larme

+0

@Larme NSMutableParagraphStyle.But에 의해 단락 스타일을 설정했습니다.하지만 모든 단락에 imapact를줍니다. 첫 번째 단락과 두 번째 단락에 다른 스타일을 설정하고 싶습니다. 예 1) 단락은 줄 간격 = 2이고 두 번째 단락은 줄 간격 = 4. –

+0

모든 코드를 표시 할 수 있습니까? – Larme

답변

4

해결 방법은 2 단락 스타일을 사용하는 것입니다.
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 
관련 문제