I am adding gradient to navigation Bar’ layer and it is working fine.
Issue arrive when I push another view Controller and pop view Controller. Parent view Controller has right Bar Button Item whose color dims when I pop View Controller.
My code is
CGRect navFrame = self.navigationController.navigationBar.frame;
navFrame.origin.y = 0.0f;
[self.navigationController.navigationBar.layer insertSublayer:[AddGradient addGradientToNavigationBar:navFrame] atIndex:0];
code for addGradientToNavigationBar is
+ (CAGradientLayer*)addGradientToNavigationBar:(CGRect)navRect {
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = navRect;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0] CGColor],
(id)[[XAppDelegate getColor] CGColor], nil];
return gradient;
}
I have the same problem.
I was tying to add gradient layer to navigation bar with the UIBarStyleBlackTranslucent style for glass effect. After searching the web and a lot of experiments I have not found the right solution for that problem. Finally I’ve came up with following work around:
// Need two additional layers to mimic UIBarStyleBlackTranslucent style
// This is needed for navigation bar buttons
// Adding layers to the first sublayer of the navigation bar layer
// After adding the gradient layer, the UIBarStyleBlackTranslucent style effect disappears
// from the bar (but not from the buttons)
// So the following is needed to mimic it
you may also want to add some borders to your layer as the borders seems to disappear.