美文网首页
QLPreviewController的使用

QLPreviewController的使用

作者: Abler | 来源:发表于2018-10-12 10:06 被阅读45次

在iOS SDK包括了QLPreviewControllerAPI在[iOS]中用于方便预览文件,它支持的文件有:
iWork文档
微软Office97以上版本的文档
RTF文档
PDF文件
图片文件
文本文件和CSV文件

1.导入库
image.png
2.代码部分
#import "ViewController.h"
#import <QuickLook/QuickLook.h>

@interface ViewController ()<QLPreviewControllerDelegate, QLPreviewControllerDataSource>
@property (nonatomic, strong) NSArray *array;
@end

@implementation ViewController
- (IBAction)did:(id)sender {
    QLPreviewController *vc = [QLPreviewController new];
    vc.dataSource = self;
    vc.delegate = self;
    [self presentViewController:vc animated:YES completion:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view, typically from a nib.
}

/*!
 * @abstract Returns the number of items that the preview controller should preview.
 * @param controller The Preview Controller.
 * @result The number of items.
 */
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller;
{
    return self.array.count;
}

/*!
 * @abstract Returns the item that the preview controller should preview.
 * @param controller The Preview Controller.
 * @param index The index of the item to preview.
 * @result An item conforming to the QLPreviewItem protocol.
 */
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index;
{
    NSURL *url = [NSURL URLWithString:self.array[index]];
    return url;
}

- (NSArray *)array {
    return @[
             @"https://ppub.jiaoyiyou.cn/708f702f-9c8f-4e33-a385-cabdb6ece7fc(%E8%AF%95%E5%8D%B7).pdf?sign=ec68c4f127d11bfb01db189b57814b7b&t=5bbf3749",
             @"https://p.jiaoyiyou.cn/000107E90M20180529.000117070110_1.jpg?sign=d22f8ff84e57389780502e89e289f7e0&t=5bbf3749",
             @"https://p.jiaoyiyou.cn/000107E90M20180529.000117070110_2.jpg?sign=696274045bb2069f7e8ee28be31e0d7c&t=5bbf3749"
             ];
}

@end

相关文章

网友评论

      本文标题:QLPreviewController的使用

      本文链接:https://www.haomeiwen.com/subject/lsywaftx.html