自定义QLPreviewController [英] Customizing QLPreviewController

查看:1184
本文介绍了自定义QLPreviewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自定义我的 QLPreviewController 的外观有一个问题。

I have an issue in customizing the appearance of my QLPreviewController.

我们可以显示一个QLPreviewController它在导航控制器中,或者在ModalViewController中呈现。由于我的navigationController的bar是自定义一点(tintColor),我推动QLPreviewController保留我的颜色方案。但是当我推它,QLPreviewController似乎有一些问题:我需要系统调用 [qlpvc reloadData] ,以便我的文件显示。

We can display a QLPreviewController by pushing it in a navigation controller, or presenting it in a ModalViewController. Since my navigationController's bar is customized a little (tintColor), I'm pushing the QLPreviewController to preserve my color scheme. But when I push it, the QLPreviewController seems to have some problems : I need to systematically call [qlpvc reloadData] so that my file is displayed.

在iOS [已编辑]中,即使使用reloadData,也不会以推送方式显示任何内容(实际上它以随机方式显示)。所以我决定只使用可靠的Modal方式可能很有趣。

In iOS [REDACTED], even with reloadData, nothing displays in the pushing way, (actually it displays but in a random way). So I decided it could be interesting to only use the reliable Modal way.

Soooo我的观点是,我想在ModalViewController中呈现我的QLPreviewController。

Soooo my point is that I want to present my QLPreviewController in a ModalViewController. It works great that way, but I can't customize the viewController appearance.

例如在 didSelectRowAtIndexPath if我这样做:

For example in a didSelectRowAtIndexPath if I do :

(我没有靠近我的来源,如果我犯错误,请原谅我)

(I don't have my sources near to me so excuse me if I do a mistake)

QLPreviewController *qlpvc = [[QLPreviewController alloc] init];  
 qlpvc.dataSource = self; // Data Source Protocol & methods implemented of course  
 No need for delegate in my case so //qlpvc.delegate = self;  
 qlpvc.currentPreviewItemIndex = [indexPath.row];  

 // The following doesn't work :  
 [qlpvc.navigationController.navigationBar setTintColor:[UIColor redColor]];  

 // The following doesn't work too :  
 [qlpvc.modalViewController.navigationController.navigationBar setTintColor:[UIColor redColor]];    

 [self presentModalViewController:qlpvc animated:YES];  
 [qlpvc release];

tl; dr版本: 如何管理自定义我的模式 QLPreviewController的外观?特别是navigationBar的tintColor?

tl ; dr version : How to manage to customize my modal QLPreviewController's appearance ? Especially the tintColor of the navigationBar ?

非常感谢。

推荐答案

这工作,但我不知道它是否会被苹果拒绝,因为它不是一个已发布的方法,可能会在未来版本的操作系统中断。

This works, but I don't know if it will be rejected by Apple as it's not a published method and may break in future versions of the OS. Works in iOS6.

添加到预览控制器数据源方法:

Add to the preview controller datasource method:

- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    for (id object in controller.childViewControllers)
    {
        if ([object isKindOfClass:[UINavigationController class]])
        {
            UINavigationController *navController = object;
            navController.navigationBar.tintColor = [UIColor colorWithRed:0.107 green:0.360 blue:0.668 alpha:1.000];
        }
    }

    NSString *pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@"MyPDFFile" ofType:@"pdf"];
    return [NSURL fileURLWithPath:pathToPdfDoc];
}

这篇关于自定义QLPreviewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆