SaifDeen
SaifDeen

Reputation: 872

iOS 7 complete UINavigationBar transparency

I'm trying to make this transparency look in a ViewControllers Navigation bar:

WANTED:

enter image description here

Till now i got only this done. The bar is not losing its color:

enter image description here

Used code:

self.navigationController.navigationBar.barTintColor = [UIColor clearColor];
self.navigationController.navigationBar.translucent = YES;

Any idea how to fix this?

Upvotes: 1

Views: 620

Answers (2)

Eike
Eike

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

Xu Yin
Xu Yin

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

Related Questions