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

后端 未结 5 1546
广开言路
广开言路 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:59

    You can use this code any where in your application(Call the method in viewWillAppeare:) by calling the method to change the navigation bar image. If You call the method in didFinishLanch means the navigation bar image is set to the whole app.

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
      [[UIDevice currentDevice] systemVersion];
        if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9)
        {
            [self customizeAppearance];
        }
    
    }
    
    - (void)customizeAppearance
    {
        UIImage *navbarimage = [[UIImage imageNamed:@"blckapplication_bar.png"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0,0,0)];
        [[UINavigationBar appearance] setBackgroundImage:navbarimage forBarMetrics:UIBarMetricsDefault];
    
        // Create resizable images    
        // Set the background image for *all* UINavigationBars
    }
    

提交回复
热议问题