Programming/iOS
화면에 PDF 띄우기
알레아
2011. 4. 7. 11:48
반응형
UIWebView를 통해서 화면에 PDF를 띄우는 소스
소스코드
PDFTestController.h
PDFTestController.m
소스코드
PDFTestController.h
@interface PDFTestController : UIViewController<UIWebViewDelegate> {
UIWebView *pdfWebView;
}
UIWebView *pdfWebView;
}
PDFTestController.m
pdfWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
pdfWebView.backgroundColor = [UIColor whiteColor];
pdfWebView.scalesPageToFit = YES;
pdfWebView.contentMode = UIViewContentModeScaleAspectFill;
pdfWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
pdfWebView.delegate = self;
[self.view addSubview:pdfWebView];
NSURL *pdfURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test.pdf" ofType:nil]];
[pdfWebView loadRequest:[NSURLRequest requestWithURL:pdfURL]];
pdfWebView.backgroundColor = [UIColor whiteColor];
pdfWebView.scalesPageToFit = YES;
pdfWebView.contentMode = UIViewContentModeScaleAspectFill;
pdfWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
pdfWebView.delegate = self;
[self.view addSubview:pdfWebView];
NSURL *pdfURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test.pdf" ofType:nil]];
[pdfWebView loadRequest:[NSURLRequest requestWithURL:pdfURL]];
반응형