IOS自定义UINavigationBar ios4与ios5通用

Here's a less-ugly solution that works for both iOS4 and 5:

@implementationUINavigationBar(CustomBackground)

-(UIImage*)barBackground
{
    return[UIImage imageNamed:@"top-navigation-bar.png"];
}

-(void)didMoveToSuperview
{
    //iOS5 only    if([self respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
    {
        [self setBackgroundImage:[self barBackground] forBarMetrics:UIBarMetricsDefault];
    }
}

//this doesn't work on iOS5 but is needed for iOS4 and earlier-(void)drawRect:(CGRect)rect
{
    //draw image    [[self barBackground] drawInRect:rect];
}

@end
posted on 2012-09-05 14:17  androidabc08  阅读(197)  评论(0编辑  收藏  举报