UINavigationBar's drawRect is not called in iOS 5.0

后端 未结 7 1890
清歌不尽
清歌不尽 2020-11-28 07:59

I\'ve overrided(placed in category, or swizzled) UINavigationBar\'s drawRect to show custom background. In iOS 5 it\'s not working. What should I do?

7条回答
  •  长情又很酷
    2020-11-28 08:04

    @implementation UINavigationBar (MyCustomNavBar)
    
    - (void)setBackgroudImage:(UIImage*)image
    {
        CGSize imageSize = [image size];
        self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, imageSize.height);
        UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:image];
        backgroundImage.frame = self.bounds;
        [self addSubview:backgroundImage];
        [backgroundImage release];
    }
    @end
    

    The above swizzling will allow you to set any custom background image for the UINavigationBar(iOS5 & iOS4).

提交回复
热议问题