Semitransparent background image (PNG24) for UINavigationBar only shows transparent after rotation
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];
精彩评论