我正在通过向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
中使用属性字符串对段落进行样式设置时,我会缺少什么/误解?