2016-04-26 10 views
0

NSParagraphStyleのparagraphPacingBeforeプロパティは何もしていないようです。私はそれが以前のプロジェクトではうまくいたとはかなり確信していますが、私が今やっていることは私の古いコードとは違うものは見当たりません。任意の提案をいただければ幸いですparagraphSpacing NSParagraphStyleの前の動作が機能しません。

textView.contentInset = UIEdgeInsetsZero; 

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; 
paragraphStyle.alignment = NSTextAlignmentJustified; 
paragraphStyle.firstLineHeadIndent = 22; 
paragraphStyle.paragraphSpacingBefore = 120; 

NSMutableDictionary *attributes = [NSMutableDictionary new]; 
[attributes setObject:[UIColor blackColor] forKey:NSForegroundColorAttributeName]; 
[attributes setObject:[UIColor clearColor] forKey:NSBackgroundColorAttributeName]; 
[attributes setObject:[UIFont fontWithName:@"Helvetica" size:19] forKey:NSFontAttributeName]; 
[attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName]; 

textView.attributedText = [[NSMutableAttributedString alloc] initWithString:@"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda." attributes:attributes]; 

:ここに私のサンプルコードです。

ありがとうございました。

答えて

0

あなたの変数textViewにInterface BuilderのUITextViewをバインドしましたか?

Objective-C Literalsを使用してください。

コード更新

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.textView.backgroundColor = [UIColor grayColor]; 

    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; 
    paragraphStyle.alignment = NSTextAlignmentJustified; 
    paragraphStyle.firstLineHeadIndent = 22; 
    paragraphStyle.paragraphSpacingBefore = 120; 

    NSDictionary *attributes = @{NSForegroundColorAttributeName:[UIColor blackColor], 
               NSBackgroundColorAttributeName: [UIColor clearColor], 
               NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:13], 
               NSParagraphStyleAttributeName: paragraphStyle 
               }; 

    self.textView.attributedText = [[NSMutableAttributedString alloc] initWithString:@"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \n Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda." attributes:attributes]; 

} 

結果:

enter image description here

+0

はご回答いただきありがとうございます。 UITextViewがバインドされ、最初の行インデントがテキストに表示されます。残念ながら、どのように属性変数を表現しても、前の段落のスペースは表示されません。 –

+0

最初の段落が存在します。しかし、あなたは各パラパラのために新しい字下げをしたいですか? –

+0

新しい章を開始するもののみ。上記のテストコードではそのどれも表されていません。このコードは、単にparagraphSpacingBeforeを動作させることで私の問題を実証するためのものです。 –

関連する問題