【问题标题】:UINavigationBar and UITabBar tint to match UIViewUINavigationBar 和 UITabBar 色调以匹配 UIView
【发布时间】:2015-04-20 03:02:44
【问题描述】:
我正在设置UINavigationBar 和UITabBar 的barTintColor。我希望我的UIView 的背景颜色完全相同,这样导航栏和标签栏就显得不可见。但是,我无法匹配颜色。
这里的背景设置为与导航栏完全相同的颜色。
这是我调整条形颜色的方法:
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.78 green:0.05 blue:0.2 alpha:1]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTranslucent:NO];
【问题讨论】:
标签:
ios
objective-c
user-interface
uinavigationbar
uitabbar
【解决方案1】:
我几乎完全复制了您的步骤,并且能够匹配颜色。
主要区别在于我将 barTintColor: 直接设置为其根视图的背景色。
这是我的代码:
itemsViewController.view.backgroundColor = [UIColor redColor];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:itemsViewController];
navController.navigationBar.barTintColor = itemsViewController.view.backgroundColor;
navController.navigationBar.tintColor = [UIColor whiteColor];
navController.navigationBar.translucent = NO;
所以我要说你的问题是你没有设置正确的 barTintColor: 因为你的 RGB 颜色值不正确。我会把你的精力集中在那里。
【解决方案2】:
你可以通过设置来摆脱这个:
navigationBar.tintColor = [UIColor redColor];
navigationBar.translucent = NO;
因此,只要您为UIView 指定与导航栏相同的颜色,它就会匹配。
将translucent 设置为NO 才是真正的解决方案。