我的顶栏有问题,我使用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 :(得分:0)
在viewWillAppear方法中调用此_initCustomTopBar
-(void)viewWillAppear:(BOOL)animated
{
[self _initCustomTopBar];
}