微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Swift PDFKit - PDFAnnotation 按钮不显示文本

如何解决Swift PDFKit - PDFAnnotation 按钮不显示文本

我正在尝试快速在 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

Apple sample code 演示了如何将小部件添加到 PDF 中,值得一试。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。