Swift PDF创建矩形? [英] Swift PDF create Rectangle?
本文介绍了Swift PDF创建矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在PDF文件上创建一个矩形,但是我不怎么做.创建一些文本或图像很简单,但是我想添加一些形状,例如矩形和圆形.
I would like to create an rectangle on an PDF File, but i dont how to do that. Its simple to create some text or images, but i would like to add some shapes like rectangles and circles.
UIGraphicsBeginPDFPageWithInfo 是否与CGContext相同?
Is the UIGraphicsBeginPDFPageWithInfo the same as the CGContext?
此刻我正在使用它:
UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil);
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);
// add some text
let mainTitle = "..."
mainTitle.drawInRect(CGRectMake(30, 110, 552, 40), withAttributes: textAttributesBoldLargeHeader)
但是如何添加自定义矩形?
But how to add a custom rectangle?
推荐答案
只需使用UIGraphicsGetCurrentContext()
获取PDF绘图上下文
并画上任何东西.简单的例子:
Just get the PDF drawing context with UIGraphicsGetCurrentContext()
and draw anything to it. Simple example:
UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil);
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);
let context = UIGraphicsGetCurrentContext()
CGContextSetFillColorWithColor(context, UIColor.blueColor().CGColor)
let rect = CGRect(x: 10, y: 10, width: 100, height: 200)
CGContextFillRect(context, rect)
UIGraphicsEndPDFContext()
这篇关于Swift PDF创建矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文