Skip to content

Instantly share code, notes, and snippets.

View MiZhen007's full-sized avatar
💭
survive

MiZhen007

💭
survive
View GitHub Profile
@Bigigrammer
Bigigrammer / HTML_to_NSAttributedString.swift
Last active June 30, 2024 07:42
This extension convert HTML to NSAttributedString each other. It works on Swift4.
extension String {
func convertAttributedString() -> NSAttributedString?{
let html = self._removePT()
let encoded = html.data(using: String.Encoding.utf8)!
let attributedOptions : [NSAttributedString.DocumentReadingOptionKey : Any] = [
.documentType : NSAttributedString.DocumentType.html,
.characterEncoding : String.Encoding.utf8.rawValue
]
do {
let attributedTxt = try NSAttributedString(data: encoded, options: attributedOptions, documentAttributes: nil)