0

I have added UINavigation bar with a background image.

But unfortunately an unwanted 1px hairline is displaying at the middle of the UINavigation Bar.

I want to hide that line, but it's not working. I have added following code.

self.navigationController.navigationBar.translucent = NO;

[self.navigationController.navigationBar setShadowImage:nil];

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navBarImg.png"] forBarMetrics:UIBarMetricsDefault];

enter image description here

Johnykutty
  • 12,091
  • 13
  • 59
  • 100
meera
  • 53
  • 2
  • 9

1 Answers1

1

if you do not need to set the navigationbar become transparent, you can use the following code

[self.navigationController.navigationBar setBackgroundImage:[self imageFromColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1]] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];

and adding the following method to generate an uiimage.

- (UIImage *)imageFromColor:(UIColor *)color {
CGRect rect = CGRectMake(0, 0, 1, 1);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;

}

Anthony Ng
  • 26
  • 3