简体   繁体   English

ios-需要带有Alpha但没有半透明模糊的导航栏

[英]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? 是否可以将导航栏设置为具有0.80f alpha且没有半透明模糊的黑色? And have views appear behind the bar? 栏后面是否有视图?

So far, I have tried setting the background to an image with alpha. 到目前为止,我已经尝试将背景设置为带有Alpha的图像。 However, the background still looks sort of opaque, and I cannot see the views behind the bar...unless I set translucent to YES. 但是,背景看起来仍然是不透明的,并且我看不到栏后面的视图...除非我将半透明设置为YES。 But setting translucent to YES also adds in a blur, which I don't want. 但是将半透明设置为YES也会增加模糊,这是我不希望的。

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. 看来 ,如果导航栏设置了背景图像,那么将半透明设置为YES将允许背景图像显示出来,而不会实际增加任何模糊。 This is exactly what I wanted. 这正是我想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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