// Finally, we draw the page and restore the graphics state for further manipulations!
CGContextDrawPDFPage(context, page);
CGContextRestoreGState(context);
}
- (void)drawRect:(CGRect)rect {
[self drawInContext:UIGraphicsGetCurrentContext()];
}
在这里使用的
pdf 文档,是放在项目的 Resources 目录下的。
再往下,就是在
Controller 中通过程序创建 PdfView 实例,并将它关联为 Controller 根视图
的子视图:
- (void)viewDidLoad {
[super viewDidLoad];
CGRect frame = CGRectMake(0, 0, 768, 1000);
PdfView *pdfView = [[PdfView alloc] initWithFrame:frame];
pdfView.backgroundColor=[UIColor whiteColor];
[self.view addSubview:pdfView];
}
这里因为是使用
iPad,因此长宽是 1000(上面留点空间)和 768。另外,需要设置底色,默
认情况下底色是黑色的,和黑体的文字在一起就显示不出文字了,我设置的是白色:
pdfView.backgroundColor=[UIColor whiteColor];
这样就可以了,而且中文啥的都没问题。