家伙, 这是我的代码:CGContext上和视网膜显示
- (void) renderPageAtIndex:(NSUInteger)index inContext:(CGContextRef)ctx {
//background
CGContextSetFillColorWithColor(ctx, [[UIColor colorWithRed:((float)238/255.0f) green:((float)233/255.0f) blue:((float)215/255.0f) alpha:1] CGColor]);
CGContextFillRect(ctx, CGRectInset(leavesView.bounds, 0, 0));
//text
CGContextSetTextDrawingMode(ctx, kCGTextFill);
CGContextSetTextMatrix(ctx, CGAffineTransformMake(1.0, 0.0, 0.0, 1.0, 0.0, 0.0));
CGContextSetFillColorWithColor(ctx, [[UIColor blackColor] CGColor]);
UIGraphicsPushContext(ctx);
CGContextSaveGState(ctx);
CGContextTranslateCTM(ctx, 0.1f, leavesView.bounds.size.height);
CGContextScaleCTM(ctx, 1.0f, -1.0f);
CGRect textRect = CGRectMake(5, 5, leavesView.bounds.size.width-10, leavesView.bounds.size.height-10);
if (pages.count > 0 && pages.count-1 >= index) {
[[pages objectAtIndex:index] drawInRect:textRect withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentLeft];
}
CGContextRestoreGState(ctx);
UIGraphicsPopContext();
}
它可以完美运行在iPhone 2G,3G,3GS,但新车型我有问题。
在视网膜上的文本被绘制不是分辨率的两倍,如在标准。
你有什么想法吗?
哦!你拯救了我的一天。真的不是那么明显。 – orkenstein 2014-10-01 14:15:26
我已经对CALayer进行了分类,我必须在init方法中执行此操作。在drawWithContext方法中抛出一个只读错误。 – 2015-08-26 23:01:47