title: UITextView html text - Refer font from project
body: <p>I am setting <code>HTML</code> text for <code>UITextView</code> using <code>NSAttributedString</code>. All tags are working except for font family and color. Font family is OpenSans which is not <strong>Microsoft supported font</strong> as mentioned <a href="https://www.tutorialspoint.com/html/html_fonts_reference.htm" rel="nofollow"><strong>here</strong></a>. So I guess I need to refer <strong>OpenSans.ttf</strong> placed in the project directory for setting font. Not sure how to set that. This is the html string :  </p>
  
  <pre><code>let htmlString = "&lt;HTML&gt;&lt;body style='font-color=rgba(74, 143, 137, 1)&gt;The Breakthrough Course is designed with varied learning preferences in mind. You will view over 40 training videos; engage in interactive learning exercises, read supplemental texts, and capture important concepts with our tailored Note Taking Guide. You will see parents from a recent in-person class “get inside the child’s world” as they participate in experiential activities. You will learn the root causes of behavior (and misbehavior) and discover over 25 positive and helpful tools from the Positive Parenting Solutions Tool Box.&lt;/br&gt;&lt;/br&gt;&lt;b&gt;Navigating the Course:&lt;/b&gt; The course design is as follows:&lt;/br&gt;&lt;/br&gt;&lt;ul&gt;&lt;li&gt;Introduction&lt;/li&gt;&lt;li&gt;Sessions 1-6&lt;/li&gt;&lt;li&gt;Wrap-up and Next Steps&lt;/li&gt;&lt;/ul&gt;&lt;/br&gt;&lt;/br&gt;You will also find resources to support your learning experience in the upper right-hand corner of each Session Page:&lt;/br&gt;&lt;/br&gt;&lt;ul&gt;&lt;li&gt;Session&lt;/li&gt;&lt;li&gt;Note Taking Guide&lt;/li&gt;&lt;li&gt;Cumulative Tool Box&lt;/li&gt;&lt;li&gt;Session FAQ’s (Collected from parent questions asked over the years in our in-person classes.)&lt;/li&gt;&lt;li&gt;Index of Terms (This will direct you to the locations throughout the course where you can find information on a particular topic.)&lt;li&gt;&lt;/br&gt;&lt;/br&gt;The Breakthrough Course is designed for you to learn at your own pace. You can review the video content and the interactive learning exercises multiple times to improve your retention. That’s the beauty of an on-line learning experience!&lt;/br&gt;&lt;/br&gt;We strongly recommend that you proceed through the course in-order. The principles and tools in each session build on the previous session. The earlier sessions lay the foundation so you understand what really motivates child behavior and the root cause of misbehavior. Once you understand the root cause, you can be confident that you are applying the appropriate tools to change the behavior for the long-term.&lt;/br&gt;&lt;/br&gt;Don’t worry – you aren’t going to have to wait until the 3rd or 4th session to begin seeing results! You will see behavioral improvements right away when you begin implementing the first tool introduced in Session 1.&lt;/body&gt;&lt;/HTML&gt;" 
  let attributedString = try? NSAttributedString(data: (htmlString.data(using: String.Encoding.unicode))!, options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil)
  text_course_title.attributedText = attributedString
  </code></pre>
  
  <p>Unfortunately the html is coming as a single line here in the question, so I request you to copy paste it in a text editor for viewing it. Even the font color is not working. It shows a blank <code>UITextView</code> if I apply font color as above.</p>