I'm building up the textual content of a UITextView
, by adding individual paragraphs one at a time to an NSMutableAttributedString
. Some of these paragraphs need to be indented, as they are hierarchical, as in:
1. ...
(a). ...
(i). ...
(ii). ...
(b). ...
...
To (try to) do the indentation, I'm using this code:
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))
and finally
textView.attributedText = attrText
where indentLevel
indicates how much a given paragraph is to be indented.
When I look at the final attributed text in the debugger, I can see the correct paragraph styling is in place, but the text on-screen is NOT indented at all; everything is left-justified.
What am I missing/misunderstanding about styling paragraphs using attributed strings in a UITextView
?