Swift PDFKit-PDF注释按钮不显示文本



我正试图用swift在PDF中构建一个目录。我的按钮没有显示任何文本,尽管边界和背景颜色正在显示。

let anno: PDFAnnotation  = PDFAnnotation(bounds: CGRect(x: xPosition, y: yPosition, width: 300, height: 40), forType: .widget, withProperties: nil)
anno.widgetFieldType = .button
anno.backgroundColor = UIColor.white
anno.fontColor = UIColor.black
anno.alignment = NSTextAlignment.center
anno.destination = PDFDestination()
anno.fieldName = "Button Third try"
anno.widgetStringValue = "button hello?"
anno.caption = "This is a test button"

anno.draw(with: PDFDisplayBox.mediaBox, in: context.cgContext)

最终,我想点击一个链接,该链接指向我的Pdf文档中的一个页面

您需要将widgetControlType设置为.pushButtonControl:

anno.widgetControlType = .pushButtonControl

有一个苹果公司的示例代码演示如何将小部件添加到PDF中,值得一看。

最新更新