0
点赞
收藏
分享

微信扫一扫

[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这些属性;

举报

相关推荐

0 条评论