I have a UITextView. I want to post the string written in this textview to the API in accordance with the HTML structure.
For example, I want the text user bolded in the Textview to be suitable for HTML.
I am using the following structure to convert HTML data from API to AttributedString and it works. But I couldn't find a solution for the opposite situation. Could you help ?
extension String {
func htmlAttributed() -> NSAttributedString? {
let htmlCSSString = "<style>" +
"html *" +
"{" +
"font-size: 12px ;" +
"font-family: AvenirNext-MediumItalic;" +
"color: #6098A1 ;" +
"}</style> \(self)"
guard let data = htmlCSSString.data(using: .utf8) else { return nil }
do {
return try NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding:String.Encoding.utf8.rawValue,], documentAttributes: nil)
} catch {
print(error.localizedDescription)
return nil
}
}
}