iOS SDK:预览和打开文档

- (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;
}
iOS SDK:预览和打开文档_第1张图片
效果图

你可能感兴趣的:(iOS SDK:预览和打开文档)