Reputation: 872
I'm trying to make this transparency look in a ViewControllers Navigation bar:
WANTED:
Till now i got only this done. The bar is not losing its color:
Used code:
self.navigationController.navigationBar.barTintColor = [UIColor clearColor];
self.navigationController.navigationBar.translucent = YES;
Any idea how to fix this?
Upvotes: 1
Views: 620
Reputation: 2431
Try this:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
And in Swift
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true
Upvotes: 5
Reputation: 3940
Please try these codes:
//set the nav bar complete transparent
[self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[UIColor clearColor]] forBarMetrics:UIBarMetricsDefault];
//remove the bottom show from nav bar
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
- (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;
}
Upvotes: 2