【问题标题】:Swift PDFKit - PDFAnnotation button not displaying textSwift PDFKit - PDFAnnotation 按钮不显示文本
【发布时间】:2021-09-19 07:52:57
【问题描述】:

我正在尝试在 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 文档中的某个页面

【问题讨论】:

    标签: swift ios-pdfkit


    【解决方案1】:

    您需要将widgetControlType 设置为.pushButtonControl

    anno.widgetControlType = .pushButtonControl

    Apple sample code 演示了向 PDF 添加小部件,值得一试。

    【讨论】:

    • 所以我的错误是我之前尝试过但没有成功,但我没有意识到我需要将 BOTH widgetFieldType 设置为按钮,并将 widgetControlType 设置为 pushButtonControl。谢谢你的帮助。编辑:现在文字是颠倒的,但我在其他地方看到过这个解决方案。
    猜你喜欢
    • 2018-10-01
    • 2021-05-12
    • 1970-01-01
    • 2022-10-24
    • 2017-03-27
    • 1970-01-01
    • 1970-01-01
    • 2021-07-30
    • 2018-06-10
    相关资源
    最近更新 更多