2011-06-17 24 views
1

我在定製我的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?

非常感謝。

回答

4

這可行,但我不知道它是否會被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]; 
} 
3

子類QLPreviewController並更改viewDidLoad:中的tintColor等。

0

如果你想保持整個應用簡約的造型,如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 

}