简体   繁体   中英

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];

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM