[英]how to add a button into QLPreviewController
Is it possible to add a new button into the toolBar or into the actionButton on the right top of QLpreviewController?是否可以将新按钮添加到工具栏或 QLpreviewController 右上角的 actionButton 中?
If yes, how i write the code?如果是,我如何编写代码?
Try setting the rightBarButtonItem
in viewDidLoad
of your custom QLPreviewController
class, like this:尝试在自定义
QLPreviewController
类的viewDidLoad
中设置rightBarButtonItem
,如下所示:
import QuickLook
import UIKit
class FileViewController: QLPreviewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.rightBarButtonItem = yourButton
}
}
Although QLPreviewController
is a subclass of UIViewController
changing navigation items has no effect.尽管
QLPreviewController
是UIViewController
的子类,但更改导航项没有任何效果。 For example, this code should theoretically work but doesn't:例如,这段代码理论上应该可以工作,但不能:
QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.navigationItem.rightBarButtonItem =
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self action:@selector(share)]
You can, however, add a toolbar to a QLPreviewController.但是,您可以向 QLPreviewController 添加工具栏。 First set up your toolbar to show when the view is loaded:
首先设置您的工具栏以显示何时加载视图:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.toolbarHidden = NO;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.navigationController.toolbarHidden = YES;
}
Next, set your toolbarItems from the QLPreviewController
delegate:接下来,从
QLPreviewController
委托设置您的工具QLPreviewController
:
- (id)previewController:(QLPreviewController *)previewController
previewItemAtIndex:(NSInteger)idx {
UIBarButtonItem *testButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Test"
style:UIBarButtonItemStylePlain
target:self
action:@selector(testButtonTapped:)];
NSArray *myToolbarItems = [NSArray arrayWithObjects:testButtonItem, nil];
previewController.toolbarItems = myToolbarItems;
[testButtonItem release];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.