QLPreviewController * preview = [[QLPreviewController alloc] init];
preview.dataSource = self;
preview.currentPreviewItemIndex = sender.tag;
preview.editing= YES;
[self presentModalViewController:preview animated:YES];
[preview release];
这两行对我不起作用。所以在写这些行之前要小心。
[preview.tabBarController.tabBar setTintColor:[UIColor blackColor]];
[preview navigationController].navigationBar setTintColor: [UIColor blackColor]];
答案 0 :(得分:12)
从iOS5开始,您可以基于实例,全局或特定容器类包含主题控件。由于iOS6以前的子类化QLPreviewController方法设置了UINavigationBar的tintColor停止工作。
考虑以下其中一项作为与iOS5和iOS6兼容的变通方法的示例:
QLPreviewController中包含的任何UINavigationBar:
[[UINavigationBar appearanceWhenContainedIn:[QLPreviewController class], nil]
setTintColor:[UIColor blackColor]];
或全局设置应用中所有UINavigationBar实例的tintColor:
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
这个策略适用于UITabBarController。
答案 1 :(得分:2)
使用此行设置UINavigationController
的样式..
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
并且要更改TabBar的颜色,只需在您班级的viewWillAppear
中添加以下代码
CGRect frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 48);
UIView *v = [[UIView alloc] initWithFrame:frame];
[v setBackgroundColor:[UIColor colorWithRed:0.1 green:0.2 blue:0.6 alpha:0.8]];
[v setAlpha:0.5];
[[self.tabBarController tabBar] insertSubview:v atIndex:0];
[v release];
答案 2 :(得分:2)
如果你想改变navigationBar的tintColor,你可以推送你的QLPreviewController而不是模态地显示它:
//i assume that you already have a navigationController
[[self navigationController] pushViewController:previewer animated:YES];
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
对于底栏,我认为这是一个UIToolbar而不是UITabBar,可能你不能改变颜色(我不知道),但你肯定不能打电话给preview.tabBarController.tabBar
。
答案 3 :(得分:0)
我找到了一个解决方案,虽然它不是正确的方法,但它有效:
创建QLPreviewController
MyQLPreviewController.h
@interface MyQLPreviewController : QLPreviewController
@end
并在该新子类的.m中复制以下代码
@implementation MyQLPreviewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UIToolbar *toolbar = [self getToolBarFromView:self.view]; //NOTE: Not the correct apperoach! could not think better solution, as iOS does not allow to access the toolbar properties in QLPreviewController
toolbar.barTintColor = [UIColor redColor];
}
- (UIToolbar *)getToolBarFromView:(UIView *)view
{
for (UIView *subView in view.subviews)
{
if ([subView isKindOfClass:[UIToolbar class]])
{
return (UIToolbar *)subView;
}
else
{
UIToolbar *toolBar = [self getToolBarFromView:subView];
if (toolBar)
{
return toolBar;
}
}
}
return nil;
}