[IOS] Rich text: custom defined indentation, line spacing

NSMutableParagraphStyle *style = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
   // line spacing
    style.lineSpacing = [ScreenAdaptUtil scalingSwitch:1.25];
    //First line indent
    style.firstLineHeadIndent = [ScreenAdaptUtil scalingSwitch:32];
   //Indent except first line
    style.headIndent = [ScreenAdaptUtil scalingSwitch:32];
   // tail indent
    style.tailIndent = [ScreenAdaptUtil scalingSwitch:-32];
    
    NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:@"abc" attributes:@{NSParagraphStyleAttributeName:style}];

 

Note: There is a place [[NSAttributedString alloc] initWithString:@"abc", if you have initialization text content in other places, initWithString:@"" can't fill in nothing, rich text will actually be invalid.

 

Top & bottom margins:

//top、left、botton、right
[_tncTextView setContentInset:UIEdgeInsetsMake([ScreenAdaptUtil scalingSwitch:56], 0, [ScreenAdaptUtil scalingSwitch:100], 0)];

 

Note: These settings need to be placed at the lower level of the view hierarchy, or will they override the background and textColor properties;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326153375&siteId=291194637