RedRoses
RedRoses

Reputation: 337

ios - Need navigation bar with alpha but NO translucent blur

Is it possible to set up the navigation bar to be black with 0.80f alpha, and without the translucent blur? And have views appear behind the bar?

So far, I have tried setting the background to an image with alpha. However, the background still looks sort of opaque, and I cannot see the views behind the bar...unless I set translucent to YES. But setting translucent to YES also adds in a blur, which I don't want.

This is what I'm doing:

CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);

UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [UIColor colorWithWhite:RGBValue(0.0f) alpha:0.80f].CGColor);
CGContextFillRect(context, rect);

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

[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

and

 UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:[MyViewController new]];
 [navController.navigationBar setTranslucent:NO];

Upvotes: 1

Views: 975

Answers (1)

RedRoses
RedRoses

Reputation: 337

Ah, I think I solved it. I just had to set translucent to YES for it to work.

It seems that if the navigation bar has a background image set, then setting translucent to YES will allow the background image to show through without actually adding any blurring. This is exactly what I wanted.

Upvotes: 2

Related Questions