- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake((CGRectGetWidth(self.view.frame)-80)/2, 200, 80, 40)];
btn.backgroundColor = [UIColor cyanColor];
[btn setTitle:@"浏览" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(previewDocument) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
- (void)previewDocument{
NSURL *URL = [[NSBundle mainBundle] URLForResource:@"iOS SDK:预览和打开文档" withExtension:@"pdf"];
if (URL) {
// Initialize Document Interaction Controller
UIDocumentInteractionController *documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
// Configure Document Interaction Controller
[documentInteractionController setDelegate:self];
// Preview PDF
[documentInteractionController presentPreviewAnimated:YES];
}
}
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *) controller {
return self;
}
![](https://img.haomeiwen.com/i2460997/a49bb764c4a1658d.png)
效果图
网友评论