title: iOS UITextView HTML: center image
body: <p>I am trying to load html content in UITextView in my iOS app.</p>
  <p>I use the following html code:</p>
  <pre><code>&lt;meta charset=utf-8&gt;
  &lt;h3 style=&quot;text-align: center;&quot;&gt;Sample text.&lt;/h3&gt;
  &lt;p&gt;&lt;img style=&quot;display: block; margin-left: auto; margin-right: auto;&quot; src=&quot;https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-logo.png?v=9c558ec15d8a&quot; width=&quot;182&quot; height=&quot;44&quot;/&gt;&lt;/p&gt;
  </code></pre>
  <p>So it should display both the text and the image in the center, however, the image is not centered:</p>
  <p><a href="https://i.stack.imgur.com/EPj9B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EPj9B.png" alt="enter image description here" /></a></p>
  <hr />
  <p><strong>Does anybody know how I can align the image to center?</strong></p>
  <p>Here is how I set the html content:</p>
  <pre><code>extension Data {
      var attributedString: NSAttributedString? {
          do {
              let options = [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html]
              return try NSAttributedString(data: self, options:options, documentAttributes: nil)
          } catch {
              print(error)
          }
          return nil
      }
  }
  extension String {
      var data: Data {
          return Data(utf8)
      }
  }
  </code></pre>
  <p>...</p>
  <pre><code>txtIntro.attributedText = htmlStr.data.attributedString
  </code></pre>
  <p>Thanks,
  Osman</p>