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

℡╲_俬逩灬. 提交于 2019-12-13 12:14:47

问题


I'm currently displaying a PDF file using the Quick Look framework on an iPad via the Modal View Controller. Works great. My problem is that since I'm displaying a PDF file the Quick Look preview is automatically adding a "Print" button. What I would like to do is replace the "Print" button with a custom "Email" button. Is this something that can be done? At first pass I thought this was going to be a somewhat trivial thing to do but at this point I'm really struggling with it. Any help would be greatly appreciated.

Thanks,

Brett


回答1:


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.




回答2:


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];
}


来源:https://stackoverflow.com/questions/5506836/how-to-add-a-custom-button-to-the-quick-look-toolbar-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!