【问题标题】:Custom navigation bar changes in one viewcontroller一个视图控制器中的自定义导航栏更改
【发布时间】:2013-07-26 07:57:14
【问题描述】:

我正在使用自定义导航栏。 在我的AppDelegate 中,我已经做到了。

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes: @{
                            UITextAttributeTextColor: [UIColor whiteColor],
                      UITextAttributeTextShadowColor: [UIColor whiteColor],
                     UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
                                 UITextAttributeFont: [UIFont fontWithName:@"Carrois Gothic" size:18.0f]
 }];

viewController 级别,我将按钮放在navigationController 内。在所有viewControllers 中,navigationbar 中只有一个按钮。

但是在一个 VC 中我需要设置 2 个按钮,并且我还更改了 navigationbarbackgroundImage。所以我在ViewDidLoad 中复制了与上面相同的代码,但现在使用了其他图像。这是有效的。

但现在我想在所有其他 VC 中使用第一个 navigationbar。所以在我的viewDidDisappear 中,我再次复制了另一张图片的代码。

以下是错误的:

  • 背景图片没有变化
  • leftbarbutton 不会消失

有人可以帮我吗?

PS:我正在使用tabbarcontroller。因此,如果我说切换 VC,我的意思是转到 tabbarcontroller 中的另一个选项卡

【问题讨论】:

    标签: ios objective-c uinavigationcontroller uitabbarcontroller uinavigationbar


    【解决方案1】:

    不要在 ViewController 中使用外观代理。直接设置背景就好了:

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar"] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setTitleTextAttributes: @{
                             UITextAttributeTextColor: [UIColor whiteColor],
                      UITextAttributeTextShadowColor: [UIColor whiteColor],
                     UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
                                 UITextAttributeFont: [UIFont fontWithName:@"Carrois Gothic" size:18.0f]
    }];
    

    【讨论】:

    • 我收到错误“程序中出现意外@”。你能帮帮我吗。
    • @chandru 你是用@{还是只用@
    • 这就是我的要求,我只是复制上面的代码并粘贴它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-05
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多