iOS 利用QuickLook查看PDF、WORD、PPT等文件和图片
.h文件中定义的urlString用来接收上个页面传过来的url,无论网上url还是本地url均可以
#import <UIKit/UIKit.h>
#import <QuickLook/QuickLook.h>
@interface QuickLookNotImageVC : UIViewController
@property (nonatomic,strong) NSString *urlString;
@end
.m文件
#import "QuickLookNotImageVC.h"
@interface QuickLookNotImageVC ()<QLPreviewControllerDataSource,QLPreviewControllerDelegate>
@property (nonatomic,strong) QLPreviewController *pre;
@end
@implementation QuickLookNotImageVC
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"附件浏览";
_pre = [[QLPreviewController alloc] init];
_pre.dataSource = self;
_pre.delegate = self;
CGRect rect = CGRectMake(0, 0, SCREEN_Width, SCREEN_Height);
_pre.view.frame = rect;
[self.view addSubview:_pre.view];
}
-(NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
return 1;
}
-(id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
return [NSURL URLWithString:_urlString];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
下图是QuickLook浏览rtf文件的截图