开发者

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

开发者 https://www.devze.com 2023-03-23 04:38 出处:网络
I\'m using a category to implement a custom background for UINavigationBar. @implementation UINavigationBar (UINavigationBarCategory)

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:CGR开发者_开发问答ectMake(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?


Try adding this after @end. See if it helps

navgationController.navigationBar.backgroundColor = [UIColor clearColor];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号