【问题标题】:UITabBar / UITabBarItem and iOS 13's Dark ModeUITabBar / UITabBarItem 和 iOS 13 的深色模式
【发布时间】:2019-11-22 11:31:12
【问题描述】:

在我们的应用程序中,我们以编程方式动态地(见下文)使用自定义 UITabBarItem。我们使用 ImageAssets 来获得深色/浅色正确的图像。但它不能 100% 工作:如果我们重新启动应用程序,就可以了。如果 iOS 切换到暗模式并且应用程序正在运行,图像将保持亮模式。想知道这是一个错误还是我现在可以设法让它工作......

UIImage *mImage = [UIImage imageNamed:@"tabBar1"];
UIImage *mImageSel = [UIImage imageNamed:@"tabBar1Sel"];

mImage = [mImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
mImageSel = [mImageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

self.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:mImage selectedImage:mImageSel];

UIEdgeInsets titleInsets = UIEdgeInsetsMake(-6, 0.0, -6.0, 0.0);
self.tabBarItem.imageInsets = titleInsets;

不显示错误消息...

【问题讨论】:

    标签: uitabbaritem ios13 ios-darkmode


    【解决方案1】:

    我们发现以编程方式创建的 UITabBarItems 存在同样的问题。

    我们尝试在 UIViewController.traitCollectionDidChange(:) 中重新创建 TabBarItem,但问题仍然存在。似乎是苹果的错误。值得注意的是,这个问题只发生在我们的 SelectedImage 上。默认的未选中状态似乎尊重 UIUserInterfaceStyle 更改(深色模式)。

    我们找到了一个临时解决方案:如果您在 UIViewController.traitCollectionDidChange(:) 中将相同的 selectedImage 重新分配给 myViewController.tabBarItem,问题就解决了。

    override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
      super.traitCollectionDidChange(previousTraitCollection)
      self.tabBarItem.selectedImage = mySelectedImage //same image asset that was used in the initializer
    }
    

    不知道为什么这会解决它,但它对我们有用。

    【讨论】:

    • 已解决...如果您单独选择选项卡 :-) 所以它可以工作,但是当您更改暗/亮模式时,我无法在所有选项卡上立即工作:/
    猜你喜欢
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2020-04-13
    • 2020-06-10
    • 2020-01-30
    • 1970-01-01
    • 2017-12-03
    相关资源
    最近更新 更多