Adding image to navigation bar

后端 未结 9 2122
一个人的身影
一个人的身影 2020-12-23 02:09

I\'d like an image to take up all of a navigation bar. This is the navigation that comes with a navigation based app. It appears on the RootViewController with the accompa

9条回答
  •  执念已碎
    2020-12-23 02:55

    In your case, this solution found in another answer would work well.

    With the "CustomImage" category added to UINavigationBar, you can then just call:

    UINavigationBar *navBar = self.navigationController.navigationBar;
    UIImage *image = [UIImage imageNamed:@"yourNavBarBackground.png"];
    [navBar setBackgroundImage:image];
    

    This code should go in the method

    - (void)viewWillAppear:(BOOL)animated
    

    of the view controller where you want to have the custom image. And, in that case you should better call:

    [navBar clearBackgroundImage]; // Clear any previously added background image
    

    before setBackgroundImage (otherwise it will be added multiple times...)

提交回复
热议问题