我目前通过使用CALayer
和renderInContext
方法从iOS中的UIView创建PDF文档。iOS从UIViews创建PDF
我面临的问题是标签的锐度。我创建了一个UILabel
子类覆盖drawLayer
像这样:
/** Overriding this CALayer delegate method is the magic that allows us to draw a vector version of the label into the layer instead of the default unscalable ugly bitmap */
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
BOOL isPDF = !CGRectIsEmpty(UIGraphicsGetPDFContextBounds());
if (!layer.shouldRasterize && isPDF)
[self drawRect:self.bounds]; // draw unrasterized
else
[super drawLayer:layer inContext:ctx];
}
这种方法让我画好的清晰的文字,然而,问题是,我不拥有控制权的其他意见。有没有什么方法可以让我为嵌入UITableView
或UIButton
的标签做类似的事情。我想我正在寻找一种方法来遍历视图堆栈,并做一些让我绘制更清晰的文本。
下面是一个例子: 本文呈现很好(我的自定义的UILabel子类)
在标准文本分段控制不是尖锐:
编辑:我得到的上下文画成我的PDF如下:
UIGraphicsBeginPDFContextToData(self.pdfData, CGRectZero, nil);
pdfContext = UIGraphicsGetCurrentContext();
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);
[view.layer renderInContext:pdfContext];
你是如何获得你的语境”用'renderInContext'重新绘制?我想知道你是否可以在那里翻倍。 – matt
更新了我的文章。 – danielbeard