• pdf渲染的小窍门

    我们都知道,在iPhone/iPad显示pdf的基本方法有两个,一个是使用UIWebView直接加载pdf文件,另一个是使用Core Graphics进行渲染(姑且称之为CGPDF方法)。UIWebView的方法是简单,只需加载pdf,其他诸如放大翻页等问题通通交给UIWebView去头痛吧。但其缺点是性能较慢,功能有限,比如要实现搜索,添加笔记等功能就比较难。而使用CGPDF方法,功能就没有限制(虽然pdf解析方面,苹果提供的文档实在有限),使用Core Graphics进行渲染,性能上也比UIWebView要提高许多,只不过翻页,放大缩小等功能都需要自己实现。

    读文章 »

     
  • 怎样从core graphics获取UIImage

    从core graphics获取UIImage的方法:

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    - (void)viewDidLoad
    {
        [super viewDidLoad];

        UIGraphicsBeginImageContext(CGSizeMake(20,20));
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        CGContextBeginPath(ctx);
        CGContextAddArc(ctx, 10, 10, 10, 0, 2*M_PI, 1);
        CGContextSetRGBFillColor(ctx, 1,0, 0, 1);
        CGContextFillPath(ctx);
        UIImage *redBall = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        UIImageView *redBallView = [[UIImageView alloc] initWithImage:redBall];
        redBallView.center = CGPointMake(160,330);
        [self.view addSubview:redBallView];
    }