2014-01-30 22 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