iOS7 QLPreviewController更改导航栏颜色?

时间:2013-11-14 09:07:48

标签: ios uinavigationbar qlpreviewcontroller

如何在QLPreviewController中设置半透明属性我已经尝试过以下代码,但它无法正常工作

  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];

由于

3 个答案:

答案 0 :(得分:3)

您可以使用:

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

我已经尝试过它并且有效。

答案 1 :(得分:2)

斯威夫特3& 4截至2018年2月,这对我有用

import QuickLook

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

这是扩展名中带有颜色功能的图像

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!)
    }
}

答案 2 :(得分:0)

[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];

注意:仅适用于iOS7