2013-06-28 77 views
0

在我的UITabBar應用程序中,我在每個選項卡中添加了NavigationController。 假設選擇的指數是0的時候,我打開我的app.In第三個標籤(選擇指數= 2)我想改變navigationBar title.And的文本顏色我使用的代碼NavigationBar文字顏色不變?

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

但其不改變索引0和2的文本顏色。索引1的顏色只有在使用上面的代碼改變顏色之前沒有點擊該選項卡時纔會改變。 我不知道這是什麼問題?任何幫助/代碼將是可觀的。

回答

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; 
} 
0

更簡單的實現將改變是感興趣的UINavigationController內的UIViewController中的導航欄的tintColor屬性。

在UIViewController,添加以下行中的視圖生命週期方法之一:

self.navigationController.navigationBar.tintColor = [UIColor greenColor];