Link in a Nsattributedstring

Asked

Viewed 32 times

0

I have a string that is actually a snippet in HTML. I use the following method to convert this snippet into a string and set it in label

let s = Descricao.data(using: String.Encoding.unicode)! 

    let attrStr = try? NSAttributedString( 

        data: s, 

        options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], 

        documentAttributes: nil) 



    lbl_Titulo.title = Nome_Convenio 

    lbl_Convenio.numberOfLines = 0 

    lbl_Convenio.sizeToFit() 

    lbl_Convenio.textAlignment = .left 

    lbl_Convenio.attributedText = attrStr

It turns out that this html can have links, which are not opening the browser when clicked. How to make these links clickable?

  • I use a Uilabel allowing links: https://github.com/TTAttributedLabel/TTAttributedLabel

1 answer

0

Would it be an option to use a Text View? will do the same effect, and in it it is possible to mark the Data Detectors textview on your storyboard for identifying links, dates, phones, etc...

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.