iphone - CGContext 和视网膜显示

标签 iphone xcode

各位, 这是我的代码:

- (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 上运行完美,但在新型号上我遇到问题。

在视网膜上绘制文本时,分辨率不会像标准中那样加倍。

你有什么想法吗?

最佳答案

尝试像这样设置图层 contentScale 变量:

layer.contentsScale = [UIScreen mainScreen].scale;

这应该使代码适应视网膜/非视网膜显示器。

关于iphone - CGContext 和视网膜显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8545547/

相关文章:

ios - UICollectionView 状态恢复 : restore all UICollectionViewCells

iphone - MPMoviePlayerController 停止 iPod 音乐播放

iphone - "Failed to upload *.app on Device "iPhone 出现错误

ios - AVD_loader.cpp : failed to get a service for display 4

Xcode 5 : The repository could not be reached

无法检测 xcode 9 仪器中的 C 泄漏

c++ - GCC 4.2 模板奇怪的错误

iphone - 固定表格 View 部分标题行的任何方法

iphone - 动画化 UIView 过渡,例如将点扩展为圆圈

iphone - iOS 中的布局 - 如何创建这样的布局?