I have a requirement like I need to show the hyperlink for particular words (Terms and privacy policy), but now I am getting the entire text with underlined. Please find the below code
let htmlData = NSString(string: descriptionText).data(using: String.Encoding.unicode.rawValue)
let options = [NSAttributedString.DocumentReadingOptionKey.documentType:
NSAttributedString.DocumentType.html]
if let attributedString = try? NSMutableAttributedString(data: htmlData ?? Data(), options: options, documentAttributes: nil) {
let style = NSMutableParagraphStyle()
style.alignment = .left
style.lineSpacing = Constants.General.lineSpacingVal
let termsFullRange = NSMakeRange(0, attributedString.length)
attributedString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.sihLegalCopyColor, range: termsFullRange)
attributedString.addAttribute(NSAttributedString.Key.font, value: UIFont.init(font: .regular, size: 12), range: termsFullRange)
attributedString.addAttribute(NSAttributedString.Key.paragraphStyle, value: style, range: termsFullRange)
termsAndCondText.linkTextAttributes = [.foregroundColor: UIColor.sihLegalCopyColor]
termsAndCondText.attributedText = attributedString
}
Text String:
"En passant et en réglant une commande <a href=\"https://www.subway.com/fr-CA/Legal/order_apptermsofuse\">, vous acceptez les modalités de la politique de confidentialité </a>et <a href=\"https://www.subway.com/fr-CA/Legal/PrivacyStatement-FWH\">relatives à l\'application et à la commande.</a>."
NOTE:vous acceptez les modalités de la politique de confidentialité -should not come with underline, but its coming with underline.
