gpt4 book ai didi

swift - 使用 UIGraphics 将贝塞尔曲线绘制为 pdf

转载 作者:行者123 更新时间:2023-11-28 06:16:55 24 4
gpt4 key购买 nike

因此 pdf 的创建效果很好,然后我有一些要添加到此 pdf 的贝塞尔曲线路径,我不确定如何添加它并设置它的位置 文件内部:

  //pdf
UIGraphicsBeginPDFContextToFile(pathForPDF, CGRect.zero, nil)
UIGraphicsBeginPDFPageWithInfo(CGRect(x: 0, y: 0, width: 1000, height: 1000), nil)

// draw the bezier
let pathFromSVGFile:UIBezierPath = // some bezier from file.

let context = UIGraphicsGetCurrentContext() // *obviously wrong
context?.addPath((pathFromSVGFile?.cgPath)!)

UIGraphicsEndPDFContext()

这不会添加路径,但我可以轻松地向该文件添加其他内容,但不确定如何添加路径和设置位置。

最佳答案

首先,您不必使用 UIGraphicsGetCurrentContext。您可以只pathFromSVGFile.stroke()。但在此之前,请确保设置笔触颜色(例如 UIColor.blue.setStroke())并设置线宽(例如 pathFromSVGFile.lineWidth = 3) .

所以,

UIGraphicsBeginPDFContextToFile(pathForPDF, CGRect.zero, nil)
UIGraphicsBeginPDFPageWithInfo(CGRect(x: 0, y: 0, width: 1000, height: 1000), nil)

// draw the bezier
let pathFromSVGFile:UIBezierPath = // some bezier from file.

UIColor.blue.setStroke()
pathFromSVGFile.lineWidth = 3
pathFromSVGFile.stroke()

UIGraphicsEndPDFContext()

关于swift - 使用 UIGraphics 将贝塞尔曲线绘制为 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44850358/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com