PDFKit iOS 11: How to change the line width of Ink annotation?

断了今生、忘了曾经 提交于 2020-01-06 12:26:52

问题


I'm drawing some ink annotations on a PDF file using PDFKit. But I can't change the width of the lines. I thought that doing:

let path = UIBezierPath()
path.lineWidth = 20 // important line
path.move(to: originPoint)
path.addLine(...)
annotation.add(path)

would be enough since modifying the lineWidth of a Bezier path works when drawing in Core Graphics. But here, it does not change anything, so how to change the line width of an annotation ?


回答1:


Use border property of PDFAnnotation to change thickness of UIBezierPath added to it.

let p = UIBezierPath()
p.move(to: CGPoint(x: 400, y: 200))
p.addLine(to: CGPoint(x: 500, y: 100))
p.addLine(to: CGPoint(x: 400, y: 0))
p.close()

let b = PDFBorder()
b.lineWidth = 10.0

let pageBounds = page.bounds(for: .artBox)
let inkAnnotation = PDFAnnotation(bounds: pageBounds, forType: PDFAnnotationSubtype.ink, withProperties: nil)
inkAnnotation.add(p)
inkAnnotation.border = b
inkAnnotation.color = .green

page.addAnnotation(inkAnnotation)


来源:https://stackoverflow.com/questions/48938804/pdfkit-ios-11-how-to-change-the-line-width-of-ink-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!