iOS 隐藏QLPreviewController右上角的分享按钮
程序员文章站
2022-03-03 12:47:36
...
预览PDF文件的时候,想通过属性隐藏右上角的分享按钮,但是属性里面没有,只能自己想方法隐藏了
.m文件
#import "YLPDFPreviewController.h" #import <QuickLook/QuickLook.h> @interface YLPDFPreviewController ()<QLPreviewControllerDelegate, QLPreviewControllerDataSource> @property(nonatomic,strong)QLPreviewController *previewController; @end @implementation YLPDFPreviewController - (void)viewDidLoad { [super viewDidLoad]; [self addChildViewController:self.previewController]; self.previewController.view.frame = self.view.bounds; [self.view addSubview:self.previewController.view]; } -(QLPreviewController *)previewController{ if (!_previewController) { _previewController = [[QLPreviewController alloc] init]; _previewController.delegate = self; _previewController.dataSource = self; [_previewController setCurrentPreviewItemIndex:0]; } return _previewController; } #pragma mark -- 文件预览的代理方法: - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller{ return 1; } - (id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index{ return _fileURL; } - (void)setFileName:(NSString *)fileName { _fileName = fileName; self.navigationItem.title = _fileName; } - (void)setFileURL:(NSURL *)fileURL { _fileURL = fileURL; [self.previewController reloadData]; } - (void)previewControllerDidDismiss:(QLPreviewController *)controller{ NSError * error; [NSFileManager.defaultManager removeItemAtURL:_fileURL error:&error]; NSLog(@"%@",error.description); if (self.dismissBlock) { self.dismissBlock(); } }
.h文件
@interface YLPDFPreviewController : UIViewController @property(nonatomic,copy)NSString * fileName; @property(nonatomic,copy)NSString * filePath; @property(nonatomic,strong)NSURL *fileURL; //预览完成回调: @property(nonatomic,copy)void(^dismissBlock)(void); @end
在使用的地方直接push即可:调用代码
YLPDFPreviewController *PDFPreviewVC = [[YLPDFPreviewController alloc]init]; PDFPreviewVC.modalPresentationStyle = 0; PDFPreviewVC.fileName = self.fileName; PDFPreviewVC.fileURL = filePath; [self.navigationController pushViewController:PDFPreviewVC animated:YES];