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;