Custom UINavigationController UIToolbar Background Image

前端 未结 4 1728
灰色年华
灰色年华 2021-01-30 07:41

I have an iPhone application using UINavigationController and would like to customize the elements with custom background images. I was able to do this for the

4条回答
  •  -上瘾入骨i
    2021-01-30 08:13

    Update:

    In iOS 5.0+ you now can use UIAppearance to customize the navigation bar.


    Another way to do this is to simply create a Category for your application's UINavigationBar class. This was pretty straightforward to implement:

    Interface:

    @interface UINavigationBar (TENavigationBar)
    
    - (void) drawRect:(CGRect)rect;
    
    @end
    

    Implementation:

    @implementation UINavigationBar (TENavigationBar)
    
    - (void) drawRect:(CGRect)rect
    {
        UIImage *image = [UIImage imageNamed:@"navigation_background"];
    
        [image drawInRect:CGRectMake(0, 
                                     0, 
                                     self.frame.size.width, 
                                     self.frame.size.height)];
    }
    
    @end
    

    Then this will be globally applied to all your UINavigationBar's automatically.

提交回复
热议问题