0

在我的UITabBar应用程序中,我NavigationController在每个选项卡中添加。假设我打开应用程序时选择的索引为 0。在我的第三个选项卡中(选择的索引 = 2)我想更改标题的文本颜色。navigationBar我正在使用代码

   [[UINavigationBar appearance] setTitleTextAttributes:
             [NSDictionary dictionaryWithObjectsAndKeys:
              [UIColor greenColor],UITextAttributeTextColor,nil]];

但它不会更改索引 0 和 2 的文本颜色。只有在使用上述代码更改颜色之前未单击该选项卡时,索引 1 的颜色才会更改。我不知道是什么问题?任何帮助/代码都将是可观的。

4

2 回答 2

0

使用它来进行相关的Navigationbar标题更改:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Here you can set View width and height as per your requirement for displaying titleImageView position in navigationbar
    UIView *backView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];

    [backView setBackgroundColor:[UIColor clearColor]];
    UILabel *titleLbl =  [[UILabel alloc]initWithFrame:CGRectMake(45, 5, 180,30)];
    [titleLbl setFont:[UIFont fontWithName:@"Arial-BoldMT" size:18.0f]];
    [titleLbl setText:@"Review Her"];
    titleLbl.backgroundColor=[UIColor clearColor];
    [titleLbl setTextColor:[UIColor colorWithRed:0/255.0f green:136/255.0f blue:230/255.0f alpha:1.0f]];
    [backView addSubview:titleLbl];

    self.navigationItem.titleView = backView;
}
于 2013-06-28T10:09:45.830 回答
0

更简单的实现是在感兴趣的 UINavigationController 内的 UIViewController 上更改 navigationBar 的 tintColor 属性。

在您的 UIViewController 中,在 View Lifecycle 方法之一中添加以下行:

self.navigationController.navigationBar.tintColor = [UIColor greenColor];
于 2013-06-28T17:16:52.407 回答