How can I show a custom image in navigation bar back button instead of default buttons which are shown by nav bar itself

前端 未结 3 1178
故里飘歌
故里飘歌 2021-02-14 22:09

On navigating to any view in an app which has navigation controller implemented, it shows a back button to go to the previous view. Is there a way I can use custom image instead

3条回答
  •  余生分开走
    2021-02-14 22:22

    It almost works like a back button. With the exception of the transition animation (after the button is tapped and current view is popped off the navigation to the right).

    The right way is to make a category.

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

提交回复
热议问题