【问题标题】:Change Navigation Bar title color and back button title color更改导航栏标题颜色和后退按钮标题颜色
【发布时间】:2009-11-05 10:19:55
【问题描述】:

我想更改UINavigationBar titleColor

我还想更改UINavigationBar backButtontextColor

我正在使用 iPhone Os sdk 3.1.2

【问题讨论】:

    标签: iphone objective-c uinavigationcontroller uinavigationbar uibarbuttonitem


    【解决方案1】:

    这对我有用。

    使用它您可以更改所有导航按钮的颜色:

     [[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];
    

    将 redColor 替换为以下内容以调整按钮的颜色:

    colorWithRed:0/255.0 green:144/255.0 blue:200/255.0 alpha:1.0// pick your color using this
    

    一定要把它放在推送的视图控制器中。不是您希望看到此后退按钮颜色的视图控制器。

    【讨论】:

      【解决方案2】:

      这个问题的一部分has already been answered

      然后,要更改后退按钮标题颜色,我建议创建一个带有标签的自定义按钮:

      UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:yourViewWithColoredText];
      navigationItem.leftBarButtonItem = buttonItem; // assign it as the left button
      

      yourViewWithColoredText 应该是包含彩色文本的自定义视图。 然后根据你的需要,你可以让它看起来像一个标准的后退按钮。

      【讨论】:

        【解决方案3】:

        您可以将 UINavigationBar.h 中定义的 titleView 设置为:

         @property(nonatomic,retain) UIView *titleView;
        // Custom view to use in lieu of a title. May be sized horizontally. Only used when item is topmost on the stack.
        

        用你想要的任何颜色弹出你自己的 UILabel。

        【讨论】:

          【解决方案4】:
          UIBarButtonItem *button = [[UIBarButtonItem alloc] init];
          [button setTintColor:[UIColor redColor]];
          

          【讨论】:

            【解决方案5】:

            在 iOS 5 和 6 上将 title 设置为 UINavigationBar

            [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:UITextAttributeTextColor]];
            

            在 iOS 7 上

            self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor blackColor]};
            


            在所有UIBarButtonItem上设置textColor

            NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                                [UIColor blackColor], UITextAttributeTextColor,
                                                [UIColor clearColor], UITextAttributeTextShadowColor, nil];
            
            [[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState: UIControlStateNormal];
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2011-10-22
              • 2015-04-28
              • 2017-01-05
              • 2023-03-19
              • 1970-01-01
              相关资源
              最近更新 更多