Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import UIKit
  2.  
  3. extension String {
  4. func html(font: UIFont) -> NSAttributedString? {
  5. do {
  6. let modifiedText = String(format: "<span style=\"font-family: \(font.fontName); font-size: \(font.pointSize)\">%@</span>", self) as String
  7.  
  8. let attrStr = try NSAttributedString(
  9. data: modifiedText.data(using: String.Encoding.unicode, allowLossyConversion: true)!,
  10. options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue],
  11. documentAttributes: nil)
  12. return attrStr
  13. } catch let error {
  14. debugPrint("label body error: \(error)")
  15. return nil
  16. }
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement