navigationBar setBackgroundImage不起作用

时间:2015-03-09 19:14:13

标签: ios objective-c background uinavigationbar

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

- (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];
}

但是,应用加载时不会更改导航栏的外观。我怎样才能解决这个问题?

所有帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

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

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


            return YES;
        }
相关问题