unselecteemtintcolor UITabBar的样式化



我在设置tabbar.unselectedItemTintColor时遇到麻烦。当我尝试设置unselectedItemTintColorscrollEdgeAppearance时,有一些奇怪的冲突。

我可以运行这段代码,事情像预期的那样工作:


UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
tabBarController.delegate = self;
tabBar.translucent = NO;
UITabBar.appearance.shadowImage = [self colorForTabBar:[UIColor darkGrayColor]]; //this is the color of the seperator line at the top.
UITabBar.appearance.unselectedItemTintColor = [UIColor purpleColor];
UIColor *tintColor =  [UIColor greenColor];
tabBar.barTintColor =  tintColor;
tabBar.backgroundImage = [self colorForTabBar:tintColor];

未选中的项目为紫色,背景为绿色。问题是,如果我向下滚动到我的视图控制器的底部,那么scrollEdgeAppearance显示而不是默认值,绿色变成透明,我的shadowImage消失了。为了解决这个问题,我试着设置:

if (@available(iOS 15.0, *)) {
tabBar.scrollEdgeAppearance = tabBar.standardAppearance;
}

这让一切都变成灰色!即使是标准的默认外观也会变成灰色。

我有了尝试设置所有外观参数如下:

if (@available(iOS 15.0, *)) {
UITabBarAppearance *appearance = [UITabBarAppearance new];
[appearance configureWithOpaqueBackground];
appearance.backgroundColor = [UIColor greenColor];
appearance.shadowImage = [self colorForTabBar:[UIColor darkGrayColor]]; //this is the color of the seperator line at the top.
tabBar.tintColor = [UIColor redColor];
tabBar.unselectedItemTintColor = [UIColor purpleColor];

tabBar.standardAppearance = appearance;
tabBar.scrollEdgeAppearance = appearance;
}

这几乎工作,除了tabBar.unselectedItemTintColor不工作,我所有的图标是灰色的,而不是紫色。

我一直在为同样的问题而挣扎。尝试在"外观"之后添加这个。shadowImage =";线:

appearance.stackedLayoutAppearance.normal.titleTextAttributes = 
@{ NSForegroundColorAttributeName : [UIColor purpleColor] };

最新更新