ChenYilong / CYLTabBarController

[EN]It is an iOS UI module library for adding animation to iOS tabbar items and icons with Lottie, and adding a bigger center UITabBar Item. [CN]【中国特色 TabBar】一行代码实现 Lottie 动画TabBar,支持中间带+号的TabBar样式,自带红点角标,支持动态刷新。【iOS13 & Dark Mode & iPhone XS MAX supported】
MIT License
6.9k stars 1.45k forks source link

[Q-A]使用方法询问:适配深色模式时,动态改变颜色和图片失效 #486

Open jieshaoli opened 4 years ago

jieshaoli commented 4 years ago

请教大神,如何对TabBar深色模式的适配。



My issue:

WHaveFun commented 4 years ago

请问解决了吗? @jieshaoli

hardyZhi commented 3 years ago

同样有这个问题,请问怎么解决?

lifeMiik commented 3 years ago

颜色可以改变,但是图片目前是改不了,一直都是 light 模式下的图片

lifeMiik commented 3 years ago

试试如下代码

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
{
    [super traitCollectionDidChange:previousTraitCollection];

    if (@available(iOS 13.0, *)){

        NSArray *navcs = self.viewControllers;
        if (previousTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {

            UIImage *selectImage = [[UIImage imageNamed:@"icon_line_sel_w"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

            for (int i = 0; i < navcs.count; i++) {
                UINavigationController *navi = navcs[i];
                navi.tabBarItem.selectedImage = selectImage;
            }

        } else {
            NSArray *navcs = self.viewControllers;

            UIImage *selectImage = [[UIImage imageNamed:@"icon_line_sel"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

            if (previousTraitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {

                for (int i = 0; i < navcs.count; i++) {
                    UINavigationController *navi = navcs[i];
                    navi.tabBarItem.selectedImage = selectImage;

                }
            }

        }
    }
}