Semitransparent background image (PNG24) for UINavigationBar only shows transparent after rotation

南楼画角 提交于 2019-12-12 06:23:54

问题


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

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?


回答1:


Try adding this after @end. See if it helps

navgationController.navigationBar.backgroundColor = [UIColor clearColor];


来源:https://stackoverflow.com/questions/6851984/semitransparent-background-image-png24-for-uinavigationbar-only-shows-transpar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!