加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – CGContext和视网膜显示

发布时间:2020-12-15 01:47:39 所属栏目:百科 来源:网络整理
导读:伙计们, 这是我的代码: - (void) renderPageAtIndex:(NSUInteger)index inContext:(CGContextRef)ctx { //background CGContextSetFillColorWithColor(ctx,[[UIColor colorWithRed:((float)238 / 255.0f) green:((float)233 / 255.0f) blue:((float)215 / 2
伙计们,
这是我的代码:

- (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));
    //text
    CGContextSetTextDrawingMode(ctx,kCGTextFill);
    CGContextSetTextMatrix(ctx,CGAffineTransformMake(1.0,0.0,1.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;

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读