当前位置:   article > 正文

iOS - 阅读PDF、docx、Excle等文件_ios refreshcurrentpreviewitem

ios refreshcurrentpreviewitem

今天给大家分享一下,阅读PDF等格式文件的原生方法,前两天给同事写了个Demo。


直接上代码了


  1. //
  2. // ViewController.m
  3. // DemoForWord
  4. //
  5. // Created by 司小文 on 2017/11/30.
  6. // Copyright © 2017年 司小文. All rights reserved.
  7. //
  8. #import "ViewController.h"
  9. #import <QuickLook/QuickLook.h>
  10. @interface ViewController ()<QLPreviewControllerDataSource>
  11. @property (nonatomic,strong) QLPreviewController *qlpreviewController;
  12. @end
  13. @implementation ViewController
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. _qlpreviewController = [[QLPreviewController alloc] init];
  17. _qlpreviewController.view.frame=CGRectMake(100, 100, 250, 500);;
  18. _qlpreviewController.dataSource = self;
  19. [_qlpreviewController refreshCurrentPreviewItem];
  20. [self addChildViewController:_qlpreviewController];
  21. [self.view addSubview:_qlpreviewController.view];
  22. }
  23. #pragma mark - qlpreViewdataSource
  24. - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
  25. return 1;
  26. }
  27. - (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
  28. {
  29. // 获取文件路径, 此处可以读取excle docx PDF等格式
  30. NSString *filePath = [[NSBundle mainBundle] pathForResource:@"demoForWord" ofType:@"docx"];
  31. return [NSURL fileURLWithPath:filePath];
  32. }
  33. - (void)didReceiveMemoryWarning {
  34. [super didReceiveMemoryWarning];
  35. // Dispose of any resources that can be recreated.
  36. }
  37. @end



这里是 demo的百度分享。




感谢观看,学以致用更感谢。





本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号