Get the right color in iOS7 translucent navigation bar

后端 未结 20 1211
囚心锁ツ
囚心锁ツ 2020-11-28 00:59

How can I get the right coloring for my translucent navigation bars in iOS 7? The navigation bar just adjusts the given color to a much brighter one. Changing brightness or

20条回答
  •  温柔的废话
    2020-11-28 01:42

    navBar.barTintColor = [UIColor orangeColor];
    navBar.translucent = YES;
    UIColor *backgroundLayerColor = [[UIColor redColor] colorWithAlphaComponent:0.7f];
    static CGFloat kStatusBarHeight = 20;
    
    CALayer *navBackgroundLayer = [CALayer layer];
    navBackgroundLayer.backgroundColor = [backgroundLayerColor CGColor];
    navBackgroundLayer.frame = CGRectMake(0, -kStatusBarHeight, navBar.frame.size.width,
            kStatusBarHeight + navBar.frame.size.height);
    [navBar.layer addSublayer:navBackgroundLayer];
    // move the layer behind the navBar
    navBackgroundLayer.zPosition = -1;
    

    Note you'll still need to muck with the the barTintColor and the backgroundLayerColor to get the exact color you want. Also, of course the colors depends on your content view's background color (e.g. white).

提交回复
热议问题