2014-01-30 24 views
0

我有我的頂欄的問題,我初始化我MainViewController顏色與在viewDidLoad使用的功能:頂欄顏色變化,當我們改變觀點

-(void)_initCustomTopBar 
{ 
NSLog(@"init"); 
UIColor *barColour = [UIColor colorWithRed:22.0f/255.0f green:61.0f/255.0f blue:121.0f/255.0f alpha:1.0f]; 
UIView *colourView = [[UIView alloc] initWithFrame:CGRectMake(0.f, -20.f, 320.f, 64.f)]; 
colourView.opaque = NO; 
colourView.alpha = .7f; 
//colourView.backgroundColor = barColour; 
self.navigationController.navigationBar.barTintColor = barColour; 
self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; 
[self.navigationController.navigationBar.layer insertSublayer:colourView.layer atIndex:1]; 
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont 
                     fontWithName:@"Helvetica Neue" size:20], NSFontAttributeName, 
          [UIColor whiteColor], NSForegroundColorAttributeName, nil]; 


self.navigationController.navigationBar.titleTextAttributes = attributes; 
} 

但是,當我改變的頂部酒吧變灰,當我點擊返回MainViewController頂部酒吧變得灰色了。 有一個想法,爲什麼它變成灰色?那有多正確?

+0

呼叫'viewWillAppear' –

+0

的方法展示你的'viewDidLoad' –

+0

不,它是像以前一樣。 – user3227545

回答

0

調用此_initCustomTopBar在viewWillAppear中方法

-(void)viewWillAppear:(BOOL)animated 
{ 

[self _initCustomTopBar]; 

} 
+0

我已經這麼做了,但也存在同樣的問題 – user3227545

+0

您能否告訴我您究竟在做什麼,意味着您的觀點改變是什麼意思? –

+0

我的意思是我有一些viewControllers,當我切換視圖控制器,頂部欄是灰色的,當我回到第一頁頂部欄的顏色也是灰色的(我用藍色初始化) – user3227545