How to add a custom button to the Quick Look toolbar in iOS?

≡放荡痞女 提交于 2019-12-04 17:16:54

Since QLPreviewController is a subclass of UIViewController, you can take advantage of -[UIViewController setToolbarItems:] to customize the toolbar.

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(emailPDF)]; 
NSArray *items = [NSArray arrayWithObject:item];
[previewController setToolbarItems:items animated:NO];   
[[self navigationController] presentModalViewController:previewController animated:YES];

Now when the user taps the "reply" icon in the toolbar, your implementation of -emailPDF will get called.

you can create a subclass of QLPreviewController like MyQLPreviewController

Then in viewWillAppear:(BOOL)animated (IMPORTANT!!)

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    UIBarButtonItem *rightRatain = self.navigationItem.rightBarButtonItem;
    UIBarButtonItem *email = ...;

    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:right, email, nil];
    [email release];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!