Achieving bright, vivid colors for an iOS 7 translucent UINavigationBar Achieving bright, vivid colors for an iOS 7 translucent UINavigationBar ios ios

Achieving bright, vivid colors for an iOS 7 translucent UINavigationBar


iOS 7.0.3 UPDATE: As you see above 7.0.3 changed things. I've updated my gist. Hopefully this will just go away as people upgrade.

Original Answer:I ended up with a hack combining the two of the other answers. I'm subclassing UINavigationBar and adding a layer to the back with some extra space to cover if any of the various height status bars are up. The layer gets adjusted in layout subviews and the color changes whenever you set barTintColor.

Gist: https://gist.github.com/aprato/6631390

setBarTintColor

  [super setBarTintColor:barTintColor];  if (self.extraColorLayer == nil) {    self.extraColorLayer = [CALayer layer];    self.extraColorLayer.opacity = self.extraColorLayerOpacity;    [self.layer addSublayer:self.extraColorLayer];  }  self.extraColorLayer.backgroundColor = barTintColor.CGColor;

layoutSubviews

  [super layoutSubviews];  if (self.extraColorLayer != nil) {    [self.extraColorLayer removeFromSuperlayer];    self.extraColorLayer.opacity = self.extraColorLayerOpacity;    [self.layer insertSublayer:self.extraColorLayer atIndex:1];    CGFloat spaceAboveBar = self.frame.origin.y;    self.extraColorLayer.frame = CGRectMake(0, 0 - spaceAboveBar, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) + spaceAboveBar);  }


The behavior of tintColor for bars has changed on iOS 7.0. It no longer affects the bar's background and behaves as described for the tintColor property added to UIView. To tint the bar's background, please use -barTintColor.You can use following code to make the app work with both ios6 and ios7.

if(IS_IOS7){    self.navigationController.navigationBar.barTintColor = [UIColor blackColor];    self.navigationController.navigationBar.translucent = NO;}else{    self.navigationController.navigationBar.tintColor = [UIColor blackColor];}

IS_IOS7 is a macro which is defined in pch file as follows.

#define IS_IOS7 ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0)


I didn't come up with this solution but it seems to work fairly well. I just added it to viewDidLoad on my subclass of UINavigationController.

Source: https://gist.github.com/alanzeino/6619253

// cheers to @stroughtonsmith for helping out with this oneUIColor *barColour = [UIColor colorWithRed:0.13f green:0.14f blue:0.15f alpha:1.00f];UIView *colourView = [[UIView alloc] initWithFrame:CGRectMake(0.f, -20.f, 320.f, 64.f)];colourView.opaque = NO;colourView.alpha = .7f;colourView.backgroundColor = barColour;self.navigationBar.barTintColor = barColour;[self.navigationBar.layer insertSublayer:colourView.layer atIndex:1];