Search code examples
iphoneiosipaduinavigationcontrolleruitoolbar

how to customize QLPreviewController's navBar and toolbar tintColor


QLPreviewController * preview = [[QLPreviewController alloc] init];
preview.dataSource = self;
preview.currentPreviewItemIndex = sender.tag;
preview.editing= YES; 
[self presentModalViewController:preview animated:YES];
[preview release];

These two lines does not work for me. so be careful before writing these lines.

[preview.tabBarController.tabBar setTintColor:[UIColor blackColor]];
[preview navigationController].navigationBar setTintColor: [UIColor blackColor]];

Problem Screenshot here


Solution

  • Since iOS5 you can theme controls based on instance, globally or when contained by specific container classes. Since iOS6 the former method of subclassing QLPreviewController to set the tintColor of the UINavigationBar stopped working.

    Consider one of the following as an example of a workaround that is compatible with iOS5 and iOS6:

    Any UINavigationBar contained within a QLPreviewController:

    [[UINavigationBar appearanceWhenContainedIn:[QLPreviewController class], nil]
            setTintColor:[UIColor blackColor]];
    

    or globally set the tintColor of all UINavigationBar instances within your app with:

     [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
    

    This same strategy works with the UITabBarController.