iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – CGContext和视网膜显示大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

伙计们, 这是我的代码: - (void) renderPageATindex:(NSUInteger)index inContext:(CGContextRef)ctx { //BACkground CGContextSetFillColorWithColor(ctx, [[UIColor colorWithRed:((float)238 / 255.0f) green:((fl
伙计们,
这是我的代码

- (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;

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

大佬总结

以上是大佬教程为你收集整理的iphone – CGContext和视网膜显示全部内容,希望文章能够帮你解决iphone – CGContext和视网膜显示所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。