NSAttributedString and html styling (bullet alignment)
<p>In my iOS app I'm using NSAttributedString to generate a list of bullets. Unfortunately I'm struggling with making the bullets look presentable. My first attempt was to use regular text and a unicode character for the bullets, basically using a string like this:</p>

<pre><code>var attributedString = NSMutableAttributedString(
    string: "Here is a list of bullets and a paragraph introducing them, note that this paragraph spans multiple lines\n" +
    "• This is the first bullet\n" +
    "• Here is a second bullet\n" +
    "• And here is a third bullet with a lot of text such that it overflows to the next line"
)
</code></pre>

<p>The result was this:</p>

<p><a href="https://i.stack.imgur.com/nccOd.png" rel="noreferrer"><img src="https://i.stack.imgur.com/nccOd.png" alt="enter image description here"></a></p>

<p>I like how the bullets look, but the overflowing text in the last bullet should be aligned with the line before and I couldn't figure out how to achieve that with plain text (without applying the same alignment to the paragraph above).</p>

<p>My 2nd attempt was to use html in NSAttributedString via NSHTMLTextDocumentType, and use <code>&lt;ul&gt;</code> and <code>&lt;li&gt;</code> elements to generate the bullets.</p>

<pre><code>let content = "Here is a list of bullets and a paragraph introducing them, note that this paragraph spans multiple lines" +
    "&lt;ul&gt;" +
         "&lt;li&gt;This is the first bullet&lt;/li&gt;" +
         "&lt;li&gt;Here is a second bullet&lt;/li&gt;" +
         "&lt;li&gt;And here is a third bullet with a lot of text such that it overflows to the next line&lt;/li&gt;" +
    "&lt;/ul&gt;"
var attributedString = try! NSMutableAttributedString(
    data: content,
    options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
    documentAttributes: nil
)
</code></pre>

<p>That fixed the first issue but introduced a new one:</p>

<p><a href="https://i.stack.imgur.com/9ex1W.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9ex1W.png" alt="enter image description here"></a></p>

<p>The bullets are now spaced too far (both from the left edge and the text on the right). I tried to use the typical html/css tricks to fix the alignment (<code>&lt;li style="text-indent: -10px;"&gt;</code>) but those styles seem to be ignored by NSAttributedString.</p>

<p>I tried to remedy this with an additional NSMutableParagraphStyle but it seems to do more harm than good. Here is what I tried:</p>

<pre><code>var paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.firstLineHeadIndent = 0
paragraphStyle.headIndent = 20
attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: attributedStringRange)
</code></pre>

<p>And here is what I got:</p>

<p><a href="https://i.stack.imgur.com/LUSPl.png" rel="noreferrer"><img src="https://i.stack.imgur.com/LUSPl.png" alt="enter image description here"></a></p>

<p>As you can see, it only made things worse, here are my issues with it:</p>

<ul>
<li>It does offset the 2nd line, but I only want that effect for the bullets, not the paragraph before (I guess I can remedy that by decreasing the range over which the effect gets applied)</li>
<li>I have to guess/hardcode the offset, in my example I picked 20 and that wasn't enough for the bullets given the current font settings, which could change</li>
<li>For some reason the bullet spacing is even more stretched out now for no reason at all, it seems like just applying a vanilla NSParagraphStyle without doing anything does this and I see no option to fix this.</li>
</ul>

<p>All I really want is for my bullet spacing to look similar to the first screenshot while the overflow indent for second line to look like the second without having to hardcode exact pixel positions. Could you guys help me out?</p>

<p>Thanks</p>