我正在生成PDF文件并在PDF文件的页脚中添加链接。它将字符串显示为突出显示,但不会重定向到网站。
我正在使用Swift 3.这是我的代码:
class CustomPrintPageRenderer: UIPrintPageRenderer {
//some code here
override func drawFooterForPage(at pageIndex: Int, in footerRect: CGRect) {
let font = UIFont.systemFont(ofSize: 10)
let textAttributes = [NSFontAttributeName:font, NSForegroundColorAttributeName:UIColor.darkGray]
let text = NSAttributedString(string: "This is a computer generated document, ", attributes: textAttributes)
let website = NSMutableAttributedString.init(string: "Click here to visit website.")
website.addAttribute(NSLinkAttributeName, value: NSURL.init(string: "www.google.com")!, range: NSMakeRange(0, website.length))
let footerContent = NSMutableAttributedString()
footerContent.append(text)
footerContent.append(website)
let textSize = getTextSize(text: footerContent.string, font: font)
let centerX = footerRect.size.width/2 - textSize.width/2
let centerY = footerRect.origin.y + 10
footerContent.draw(at: CGPoint(x: centerX, y: centerY))
}
}