79214966

Date: 2024-11-22 12:15:21
Score: 1
Natty:
Report link

I think I found a workaround:

  1. Draw text without a link attribute:

     let text = "https://www.stackoverflow.com"
    
     let attributes = [
          NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14),
          NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue,
          NSAttributedString.Key.foregroundColor: UIColor.black, // Set colour here
     ] as [NSAttributedString.Key : Any]
    
     text.draw(at: textViewOrigin, withAttributes: attributes)
    
  2. Create PDFDocument from the url where PDF is rendered and allow PDFKit add hyperlink automatically:

     let pdfDocument = PDFDocument(url: url)
     let pdfData = pdfDocument?.dataRepresentation()
    

Text attributes will be those set in Step 1 and thanks to some magic that happens in PDFDocument(url: url) link will be clickable. Then we can share PDF or whatever else was the goal.

Reasons:
  • Blacklisted phrase (0.5): thanks
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
Posted by: Shalugin