How can I change the background image for my NavigationBar on a per page basis?

后端 未结 5 1547
广开言路
广开言路 2020-12-29 00:38

I\'ve been looking around for a way to change the background image of my NavigationBar and control the appearance of my NavigationBar as the user n

5条回答
  •  梦谈多话
    2020-12-29 00:54

    I believe this to be the first actual answer to this for iOS5, the main problem being the "removal" of the background image once you are done. Well, just retain the existing image and put it back when you are done.

    @implementation MyViewController {
        UIImage *_defaultImage;
    }
    
    - (void)viewWillAppear:(BOOL)animated {   
        _defaultImage = [self.navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault];
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bar.png"] forBarMetrics:UIBarMetricsDefault];
    }
    
    - (void)viewWillDisappear:(BOOL)animated {
        [self.navigationController.navigationBar setBackgroundImage:_defaultImage forBarMetrics:UIBarMetricsDefault];
    }
    

提交回复
热议问题