Objective-C: Background image and title in Navigation Bar

前端 未结 2 1205
小鲜肉
小鲜肉 2021-01-24 22:22

In need a background image AND a title in my Navigation Bar. For the image I write a category:

@implementation UINavigationBar(MyNavigationBar)
- (void)setBackgr         


        
相关标签:
2条回答
  • 2021-01-24 22:44

    After IOS5 You should do this, for example in AppDelegate


     UIImage *img = [[UIImage imageNamed:@"image.png"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    [[UINavigationBar appearance] setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent];
    [[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:0 green: 0 blue:0  alpha:1]];
    

    0 讨论(0)
  • 2021-01-24 22:57

    I got it!

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

    See Background image for navigation view

    0 讨论(0)
提交回复
热议问题