[IOS]富文本:自定义定义缩进、行距

NSMutableParagraphStyle *style = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
   //行距
    style.lineSpacing = [ScreenAdaptUtil scalingSwitch:1.25];
    //首行缩进
    style.firstLineHeadIndent = [ScreenAdaptUtil scalingSwitch:32];
   //除首行外缩进
    style.headIndent = [ScreenAdaptUtil scalingSwitch:32];
   //尾部缩进
    style.tailIndent = [ScreenAdaptUtil scalingSwitch:-32];
    
    NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:@"abc" attributes:@{NSParagraphStyleAttributeName:style}];

注意:这里有一个地方[[NSAttributedString alloc] initWithString:@"abc",如果你在其他地方有初始化文本内容的话,initWithString:@""不能什么也不填,富文本实际会失效。

顶部&底部margin:

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

注意:这些设置需要放在view层级的下层,要不会覆盖掉background、textColor这些属性;

猜你喜欢

转载自jameskaron.iteye.com/blog/2393882