2

How can i set the translucent property in QLPreviewController i have tried the below code but its not working

  QLPreviewController *previewer = [[QLPreviewController alloc] init];
// Set data source
[previewer setDataSource:self];
[previewer setDelegate:self];
previewer.edgesForExtendedLayout = UIRectEdgeNone;
[previewer setCurrentPreviewItemIndex:index];
[self.navigationController.navigationBar setTranslucent:NO];
[self.navigationController setToolbarHidden:NO];
[[self navigationController] pushViewController:previewer animated:YES];

Thanks

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Sunny Shah
  • 12,990
  • 9
  • 50
  • 86

3 Answers3

3

You can use this:

UINavigationBar *navBar =  [UINavigationBar appearanceWhenContainedIn:[QLPreviewController class], nil];
[navBar setBackgroundImage:[UIImage imageNamed:@"navigation-bg-ios7.png"] forBarMetrics:UIBarMetricsDefault];

I've tried it and it works.

Maystro
  • 2,907
  • 8
  • 36
  • 71
2

Swift 3 & 4 this works for me as of February 2018

import QuickLook

UINavigationBar.appearance(whenContainedInInstancesOf: [QLPreviewController.self]).setBackgroundImage(UIImage.init(color: primaryColor), for: .default)

this is the image with color func in an extension

extension UIImage {

    //image with color
    convenience init?(color: UIColor) {
        let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0)
        UIGraphicsBeginImageContext(rect.size)
        let path = UIBezierPath(rect: rect)
        color.setFill()
        path.fill()
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        self.init(cgImage: image!.cgImage!)
    }
}
Stan
  • 1,513
  • 20
  • 27
0
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];

Note: Only works in iOS7

valheru
  • 2,552
  • 3
  • 20
  • 40