UINavigationBar 和 UITabBar 色调匹配 UIView
UINavigationBar and UITabBar tint to match UIView
我正在设置 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];
我几乎完全复制了你的步骤并且能够匹配颜色。
主要区别在于我将 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 颜色值不正确。我会把你的精力集中在那里。
您只需设置即可摆脱此问题:
navigationBar.tintColor = [UIColor redColor];
navigationBar.translucent = NO;
因此,只要您为 UIView
提供与导航栏相同的颜色,它就会匹配。
将translucent
设置为NO
才是真正的解决方案。
我正在设置 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];
我几乎完全复制了你的步骤并且能够匹配颜色。
主要区别在于我将 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 颜色值不正确。我会把你的精力集中在那里。
您只需设置即可摆脱此问题:
navigationBar.tintColor = [UIColor redColor];
navigationBar.translucent = NO;
因此,只要您为 UIView
提供与导航栏相同的颜色,它就会匹配。
将translucent
设置为NO
才是真正的解决方案。