NSAttributedString
및 NSParagraphStyle
과 NSParagraphAttributeName
을 조합하여 사용하는 것이 좋습니다. 여기
은 예입니다 : 초기 텍스트를 포맷하는 방법을 따라 지금
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:yourString];
int indent1 = 0;
int indent2 = 20;
int indent3 = 2*indent2;
NSMutableParagraphStyle *styleTitleByNumber = [[NSMutableParagraphStyle alloc] init];
[styleTitleByNumber setFirstLineHeadIndent:indent1];
[styleTitleByNumber setHeadIndent:indent1];
NSMutableParagraphStyle *styleTitleByLetter = [[NSMutableParagraphStyle alloc] init];
[styleTitleByLetter setFirstLineHeadIndent:indent2];
[styleTitleByLetter setHeadIndent:indent2];
NSMutableParagraphStyle *styleSimpleText = [[NSMutableParagraphStyle alloc] init];
[styleSimpleText setFirstLineHeadIndent:indent3];
[styleSimpleText setHeadIndent:indent3];
[attributedString addAttribute:NSParagraphStyleAttributeName
value:styleTitleByNumber
range:rangeOfTitleByNumber];
[attributedString addAttribute:NSParagraphStyleAttributeName
value:styleTitleByLetter
range:rangeOfTitleByLetter];
[attributedString addAttribute:NSParagraphStyleAttributeName
value:styleSimpleText
range:rangeOfSimpleText];
[yourTextView setAttributedText:attributedString];
, 내가 당신에게합니다 (NSRange
매개 변수에 대한) 어떤 스타일을 적용 할 위치를 알 수있는 방법을 떠나, 또는 당신은 또한 할 수있는, 다른 부분이 분리되어있는 경우 NSAttributedString
에 직접적인 효과를 적용한 다음 모두 결합하십시오.
잘 모르겠지만 @ "첫 줄 \ n \ t 세컨드 라인 탭 \ n \ t \ t 세 번째 줄은 두 개의 탭이 있습니다"와 같은 탭을 사용해보십시오. 따라서 "\ t"는 탭이고 "\ n"은 줄 바꿈 –
@DavidG입니다. 처음에는 그 생각을했지만 UITextView의 너비가 아이폰과 ipad 모두 다른 그림으로 나타납니다. 그래서 나는 그것을 사용할 수 없다. –