在定制我的QLPreviewController外观时,我遇到了一个问题。
我们可以通过在导航控制器中推送QLPreviewController或在ModalViewController中显示它来显示它。因为我的导航控制器的酒吧是定制的一点(tintColor),我推动QLPreviewController以保留我的配色方案。但是当我按下它时,QLPreviewController似乎有一些问题:我需要系统地调用qlpvc reloadData,以便显示我的文件。
在iOS中,即使使用reloadData,也不会以推送方式显示任何内容(实际上,它是以随机方式显示的)。所以我决定只使用可靠的模态方式可能会很有趣。
因此,我的观点是,我想把我的QLPreviewController呈现在ModalViewController中。它的工作方式很好,但我不能自定义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的外观?尤其是tintColor of navigationBar?
非常感谢。
发布于 2012-11-08 12:15:45
这是可行的,但我不知道它是否会被苹果拒绝,因为它不是一个公布的方法,可能会破坏未来版本的操作系统。在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];
}发布于 2011-12-07 02:22:16
子类QLPreviewController,并在viewDidLoad:中更改tintColor等。
发布于 2014-04-10 04:01:04
如果您试图在整个应用程序中维护简单的样式(如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
}https://stackoverflow.com/questions/6386492
复制相似问题