导航栏 setBackgroundImage 不工作

navigationBar setBackgroundImage not working

我正在尝试使用以下代码设置导航栏的背景图片:

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

viewController = [[ViewController alloc] init];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[viewController presentViewController:navigationController animated:YES completion:NULL];

[self createInterface];


}

- (void) createInterface {
[viewController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bar.png"] forBarMetrics:UIBarMetricsDefault];
}

但是,应用加载时导航栏的外观没有任何变化。我怎样才能解决这个问题?

感谢所有帮助。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
        {

          UIImage *navBackgroundImage = [UIImage imageNamed:@"navbar_bg"];
            [[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];


            return YES;
        }