【问题标题】:navigationBar setBackgroundImage not working导航栏 setBackgroundImage 不起作用
【发布时间】:2015-03-09 19:14:12
【问题描述】:

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

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

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

感谢所有帮助。

【问题讨论】:

    标签: ios objective-c background uinavigationbar


    【解决方案1】:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
            {
    
              UIImage *navBackgroundImage = [UIImage imageNamed:@"navbar_bg"];
                [[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
    
    
                return YES;
            }
    

    【讨论】:

    • 它将在所有 ViewControllers 中为 NavigationBar 设置背景图像
    • 对于其他任何人,此代码都放在您的 AppDelegate 中。谢谢阿德南! :)
    • 有你的勾号 :P 再次感谢!
    猜你喜欢
    • 2021-09-04
    • 2019-01-15
    • 2017-03-06
    • 2016-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多