How to put an image as the navigation bar title

前端 未结 7 1644
忘掉有多难
忘掉有多难 2020-12-04 09:04

I want to put a .png image in the middle of the navigation bar instead of the title written in text. Could you please let me know how to do that?

Thanks.

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 09:42

    Searching for an answer to this question, I've found a nice and simple solution in the Apple Discussions forum, overriding -(void)drawRect:(CGRect)rect for UINavigationBar :

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

提交回复
热议问题