UINavigationBar的半透明背景图像(PNG24)仅在旋转后显示透明 [英] Semitransparent background image (PNG24) for UINavigationBar only shows transparent after rotation

查看:92
本文介绍了UINavigationBar的半透明背景图像(PNG24)仅在旋转后显示透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个类别来实现 UINavigationBar 的自定义背景。

I'm using a category to implement a custom background for UINavigationBar.

@implementation UINavigationBar (UINavigationBarCategory)

- (void)drawRect:(CGRect)rect 
{
    UIImage *img  = [UIImage imageNamed: @"TopNav-YellowRule.png"];
    [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];

}
@end

我正在使用的图片是一个半透明的PNG24。当应用程序加载 UINavigationBar 的背景时显示正常但不是半透明 - 我看不到 UINavigationBar

The image that I am using is a semitransparent PNG24. When the app loads the background of the UINavigationBar shows up just fine but is not semitransparent - I cannot see the views that are below the UINavigationBar.

然而,当我旋转设备时,图像突然变为半透明并且工作正常。旋转时发生的任何想法都允许图像按预期显示?有没有办法解决它,以便在旋转之前在初始加载时正确显示?

When I rotate the device, however, the image is suddenly semitransparent and works just fine. Any ideas what is happening on rotate that is allow the image to display as intended? Is there a way to fix it so that it displays properly on initial load, before a rotation?

推荐答案

尝试在@之后添加此项结束。看看是否有帮助

Try adding this after @end. See if it helps

navgationController.navigationBar.backgroundColor = [UIColor clearColor];

这篇关于UINavigationBar的半透明背景图像(PNG24)仅在旋转后显示透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆