我正在构建 a 的文本内容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
whereindentLevel
表示给定段落的缩进量。
当我在调试器中查看最终的属性文本时,我可以看到正确的段落样式已就位,但屏幕上的文本根本没有缩进;一切都是左对齐的。
关于在 a 中使用属性字符串来设置段落样式,我有什么遗漏/误解UITextView
?