我想要改变指定控制器的导航栏的背景颜色。
切换应用时,我设置的导航栏的背景颜色失效了,感觉被初始化了。
进入App,设置没问题。请看导航栏。
切换应用时,设置的导航栏的背景颜色失效
搞不定。我列举一下,试过的代码:
1. 设置 statusBar.backgroundColor,
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = [UIColor redColor ];
}
2. 在 statusBar上插入子视图.
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
UIView * backgroundColorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 20) ];
backgroundColorView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
backgroundColorView.backgroundColor = [UIColor redColor ];
[statusBar.subviews.firstObject insertSubview: backgroundColorView atIndex:0];
3. 插入 layer,也一样, CALayer
我在Github上面,找到了实现的源码,通过Runtime 实现的。 但是我的领导,不准许我使用Runtime实现。
问下 不使用Runtime 的实现方式?
感觉不难,就是我没什么头绪。
望解决。
:-)
直接在 navigationBar 上添加 view,我这边可以,LZ试下
UINavigationBar *navigationBar = self.navigationController.navigationBar;