缩进UITextView的特定个别段落

时间:2019-05-07 14:09:17

标签: ios uitextview nsattributedstring nsmutableattributedstring nsparagraphstyle

我正在通过向UITextView一次添加一个段落来建立NSMutableAttributedString的文本内容。这些段落中的某些段落是缩进的,因为它们是分层的,例如:

1. ...    
   (a). ... 
       (i). ...
       (ii). ...
   (b). ...
...

要(尝试)进行缩进,我正在使用以下代码:

let paraStyle = NSMutableParagraphStyle()
paraStyle.firstLineHeadIndent = CGFloat(indentLevel * 20)
paraStyle.headIndent = CGFloat(indentLevel * 20) 
attrText.addAttribute(.paragraphStyle, value: paraStyle, range:NSRange(location: 0, length: attrText.length))

最后

textView.attributedText = attrText

其中indentLevel指示给定段落要缩进多少。

当我在调试器中查看最终的属性文本时,可以看到正确的段落样式,但是屏幕上的文本根本没有缩进;一切都左对齐。

UITextView中使用属性字符串对段落进行样式设置时,我会缺少什么/误解?

0 个答案:

没有答案
相关问题