【发布时间】:2011-10-20 21:19:32
【问题描述】:
我在网上看到过很多这样的问题,但似乎没有人真正知道答案?
我正在使用 QLPreviewController 来显示 PDF 文档。我第一次使用 UIWebView,但出于性能原因,建议我使用 QLPreviewController 来处理更大的文档。
我想要的是右上角的 4 个自定义 UIBarButtonItem(打印按钮在哪里)。
我设法在底部获得了一个自定义工具栏,但这并不是我真正想要的。
考虑到无法在打印按钮的位置添加自定义按钮,我还是想去掉打印按钮,改用自定义工具栏。
编辑(解决方案): 我不久前找到了解决方案,但没有更新这篇文章,所以这是我解决问题的方法:
我手动添加所有按钮:
// Create a toolbar to have the buttons at the right side of the navigationBar
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 180, 44.01)];
[toolbar setTranslucent:YES];
// Create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:4];
// Create button 1
button1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(button1Pressed)];
[buttons addObject:button1];
// Create button 2
button2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(button2Pressed)];
[buttons addObject:button2];
// Create button 3
button3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(button3Pressed)];
[buttons addObject:button3];
// Create a action button
openButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(openWith)];
[buttons addObject:openButton];
// insert the buttons in the toolbar
[toolbar setItems:buttons animated:NO];
// and put the toolbar in the navigation bar
[[self navigationItem] setRightBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:toolbar]];
【问题讨论】:
-
RBFilePreviewer 现在支持您正在寻找的功能,无需修改。
-
我的回答是否足以被接受并获得赏金?
-
这不是我真正想要的,我现在遇到了 QLPreviewController 的另一个问题:stackoverflow.com/questions/7038438/… 但我会排除你的答案,因为它是最好的(也是唯一的)一个,这对我有点帮助。
-
不能在ios6下,现在是一个单独的应用程序::见stackoverflow.com/questions/12675378/…
标签: iphone objective-c ipad uibarbuttonitem qlpreviewcontroller