Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- extension String {
- func html(font: UIFont) -> NSAttributedString? {
- do {
- let modifiedText = String(format: "<span style=\"font-family: \(font.fontName); font-size: \(font.pointSize)\">%@</span>", self) as String
- let attrStr = try NSAttributedString(
- data: modifiedText.data(using: String.Encoding.unicode, allowLossyConversion: true)!,
- options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue],
- documentAttributes: nil)
- return attrStr
- } catch let error {
- debugPrint("label body error: \(error)")
- return nil
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement