赞
踩
今天给大家分享一下,阅读PDF等格式文件的原生方法,前两天给同事写了个Demo。
直接上代码了
- //
- // ViewController.m
- // DemoForWord
- //
- // Created by 司小文 on 2017/11/30.
- // Copyright © 2017年 司小文. All rights reserved.
- //
-
- #import "ViewController.h"
- #import <QuickLook/QuickLook.h>
- @interface ViewController ()<QLPreviewControllerDataSource>
- @property (nonatomic,strong) QLPreviewController *qlpreviewController;
-
- @end
-
- @implementation ViewController
-
- - (void)viewDidLoad {
- [super viewDidLoad];
- _qlpreviewController = [[QLPreviewController alloc] init];
- _qlpreviewController.view.frame=CGRectMake(100, 100, 250, 500);;
- _qlpreviewController.dataSource = self;
- [_qlpreviewController refreshCurrentPreviewItem];
- [self addChildViewController:_qlpreviewController];
- [self.view addSubview:_qlpreviewController.view];
- }
-
- #pragma mark - qlpreViewdataSource
- - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
- return 1;
- }
-
- - (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
- {
- // 获取文件路径, 此处可以读取excle docx PDF等格式
- NSString *filePath = [[NSBundle mainBundle] pathForResource:@"demoForWord" ofType:@"docx"];
- return [NSURL fileURLWithPath:filePath];
- }
-
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
-
-
- @end

感谢观看,学以致用更感谢。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。