0

From server I get a string with html tag, it's like that:

  "It's a test - <a href=\"https://apple.com\" target=\"_blank\">Apple</a>""

I use this function to convert it to NSAttributedString.

  func convertHtmlTagsToString(text: String) {
      let attributedString = Data(text.utf8)      
      
      if let attributedString = try? NSAttributedString(data: attributedString, options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil) {
         
         label.attributedText = attributedString
      }
   }

My first problem is I can't change the color of the label text, it's black, and my second problem is, how I can make the url part clickable that I can open safari with that link.

Thank you so much.

Robert kont
  • 165
  • 1
  • 8
  • 1
    With a label you cannot unless you implement the logic by yourself. Use a `UITextView` with data detector instead. – Sulthan Sep 15 '20 at 16:25
  • Thanks, could you please tell me how to change its text color? – Robert kont Sep 15 '20 at 16:26
  • Ideally, using CSS. You are interpreting the data as HTML, therefore you can just wrap it into a ` – Sulthan Sep 15 '20 at 16:27
  • https://stackoverflow.com/questions/55826193/swift-the-html-data-converted-to-nsattributed-string-doesnt-make-the-links-cli/ – Larme Sep 15 '20 at 16:35

0 Answers0