How to use “pdfView” in object library in iOS?

2019-09-08 09:30发布

I see in "object library" pdfView is there, but, when I click on .XIB it got disappers.How can I use this for iPhone or IPad development? Plaese provide me any example links.Thanks.

Note: Plaese do not tell me to use any 3rd party lib,because I'm already refering two.This i don't want ot use going forword.

2条回答
Explosion°爆炸
2楼-- · 2019-09-08 09:54

PDFView is only for cocoa(OSX) not for iOS.

A PDFView object encapsulates the functionality of PDF Kit into a single widget that you can add to your application

PDFKit only available in OSX.

In iOS to display pdf pages you don't want use any third party libraries, you can draw the pdf view by creating a custom view override the draw something like

Get the pdf document

  NSString *pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@"aa" ofType:@"pdf"];
  NSURL *pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc];
  document = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl);
  currentPage = 1;     

In drawRect

-(void)drawRect:(CGRect)rect
{
    CGPDFPageRef page = CGPDFDocumentGetPage(document, currentPage);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSaveGState(ctx);
    CGContextTranslateCTM(ctx, 0.0, [self bounds].size.height);
    CGContextScaleCTM(ctx, 1.0, -1.0);
    CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, [self bounds], 0, true));
    CGContextDrawPDFPage(ctx, page);    
    CGContextRestoreGState(ctx);
}
查看更多
甜甜的少女心
3楼-- · 2019-09-08 10:17

Are you posting two questions that are pretty much the same?

A couple of minutes ago you posted this: Object library not visible when click on .XIB in xcode ios

My answer still stands, you have chosen a OSX xib NOT an iOS xib.

If you want to show a PDF in an iOS app, you could add it to a UIWebView. Have a look at this question for details: iPhone : can we open pdf file using UIWebView?

查看更多
登录 后发表回答