简体   繁体   中英

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

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 ?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM