CGContext和视网膜显示 [英] CGContext and retina display
本文介绍了CGContext和视网膜显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
伙计们,
这是我的代码:
guys, this is my code:
- (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上运行完美,但在新机型上我有问题。
It works perfect on iPhone 2G, 3G, 3GS, but on new models I have problems.
在视网膜上的文字不会像标准中那样使分辨率加倍。
On the retina text is drawn not to double the resolution, as in the standard.
你有什么想法吗?
推荐答案
尝试像这样设置图层contentScale变量:
Try setting the layers contentScale variable like this:
layer.contentsScale = [UIScreen mainScreen].scale;
这应该使代码适应视网膜/非视网膜显示。
This should make the code adapt to retina/nonretina displays.
这篇关于CGContext和视网膜显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文