I am creating NSAttributedString by using html:
let htmlString = "<body style='padding-left:50px'><h1>Hello World</h1><div><a href=https://apple.com/offer/samsung-faq/>Click Here</a></div><p>This is a sample text</p><pre>This is also sample pre text</pre></body>"
And here i am setting it to UILabel by using extension method
someLabel.attributedText = htmlString.htmlToAttributedString
NSAttributedString Extension:
extension String {
var htmlToAttributedString: NSAttributedString? {
guard let data = data(using: .utf8) else { return NSAttributedString() }
do {
return try NSAttributedString(data: data, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)
} catch {
return NSAttributedString()
}
}
}
Here i want an callback method to detect link which is there in html string as anchor tag. How will i get an event on click and how can i get the url in that event callback ?
Please help...