using image or tint color on uinavigationbar in iphone?

前端 未结 7 1779
自闭症患者
自闭症患者 2020-12-24 09:58

how do i show a background image on a navigation bar or give tint color to the navigation bar in a native iphone application??

7条回答
  •  既然无缘
    2020-12-24 10:29

    You can override UINavigationBar drawRect. The code can be placed to appDelegate.m I've tested it and it's working on 3x and 4x iOS.

    @implementation UINavigationBar (UINavigationBarCategory)
    - (void)drawRect:(CGRect)rect {
        UIColor *color = [UIColor blackColor]; //tint color
        UIImage *img = [UIImage imageNamed: @"navBarBg.png"]; // your image
        [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        self.tintColor = color;
     }@end
    

提交回复
热议问题