定制QLPreviewController
我在定制我的QLPreviewController
的外观时遇到问题。定制QLPreviewController
我们可以通过将其推入导航控制器或将其呈现在ModalViewController中来显示QLPreviewController。由于我的导航控制器的酒吧是自定义一点(tintColor),我推QLPreviewController来保存我的配色方案。但是当我推送它时,QLPreviewController似乎有一些问题:我需要系统地调用[qlpvc reloadData]以便显示我的文件。
在iOS [编辑]中,即使使用reloadData,也没有任何内容以推送的方式显示(实际上它以随机方式显示)。所以我决定只使用可靠的Modal方法会很有趣。
Soooo我的观点是我想在ModalViewController中呈现我的QLPreviewController。它很好用,但我无法自定义viewController的外观。
例如,在didSelectRowAtIndexPath
如果我这样做:
(我没有我的消息来源靠近我,所以原谅我,如果我做了一个错误)
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?
非常感谢。
这可行,但我不知道它是否会被Apple拒绝,因为它不是已发布的方法,可能会在未来版本的操作系统中打破。适用于iOS6。
添加到预览控制器的数据源方法:
- (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并更改viewDidLoad:
中的tintColor等。
如果你想保持整个应用简约的造型,如tintColor,你应该考虑使用很多的UIView类UIAppearance选择。以下示例自定义UINavigationBar的所有实例,包括QLPreviewController中显示的那些实例:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
//..
[self initAppearance];
return YES;
}
-(void)initAppearance{
UINavigationBar* defaultNavigationBar = [UINavigationBar appearance];
UIImage *backgroundImage = [UIImage imageNamed:@"MY_IMAGE.png"]
NSDictionary *defaultNavigationBarDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Futura-Medium" size:19], NSFontAttributeName,
[UIColor blueColor], UITextAttributeTextColor,
[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, 2.0f)], UITextAttributeTextShadowOffset,
nil];
defaultNavigationBar.titleTextAttributes = defaultNavigationBarDictionary; //iOS5
//[defaultNavigationBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault]; //iOS5
[defaultNavigationBar setBarTintColor:[UIColor redColor]]; //iOS7
[defaultNavigationBar setShadowImage:[[UIImage alloc] init]]; //iOS6, removes shadow
[defaultNavigationBar setTitleVerticalPositionAdjustment:0.0f forBarMetrics:UIBarMetricsDefault]; //iOS5
[defaultNavigationBar setBackIndicatorImage:[UIImage imageNamed:@"BACK_ARROW.png"]]; //iOS7
[defaultNavigationBar setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"BACK_ARROW.png"]]; //iOS7
}