0

I'm trying to change my navigation bar colour and I do it with this famous command:

navController.navigationBar.tintColor = [UIColor colorWithRed:57/255.0 green:50/255.0 blue:36/255.0 alpha:0];

(or alpha:1)

The problem is that the Color appears as graduate (white on the top edge, dark on the button)- how can i get rid of this "effect" and make my colour uniform

rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

0

To remove the gradient you need to subclass UINavigationBar and implement drawRect: to draw your chosen colour.

Wain
  • 118,658
  • 15
  • 128
  • 151
0

If you don't want to subclass, you could always just make a 1x1 image in the color you want and set it as the bar's background image:

UIImage *image = [self imageWithColor:[UIColor redColor]];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];


- (UIImage *)imageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}

Source for imageWithColor:

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281