首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改单个选项卡栏图标的unselectedItemTintColor

更改单个选项卡栏图标的unselectedItemTintColor
EN

Stack Overflow用户
提问于 2020-05-26 18:56:00
回答 1查看 43关注 0票数 0

我有一个包含5个项目的UITabBarController子类。

第五项是用户头像。

代码语言:javascript
复制
final class HomeSceneViewController: UITabBarController {

  init(tabs: [UIViewController]) {
    super.init(nibName: nil, bundle: nil)
    viewControllers = tabs

    configureUI()
  }

  required init?(coder: NSCoder) {
    return nil
  }
}

private extension HomeSceneViewController {
  func configureUI() {
    view.backgroundColor = .white
    tabBar.unselectedItemTintColor = .red
    tabBar.tintColor = .blue
  }
}

目前每个视图控制器使用tabBarItem = UITabBarItem(title: nil, image: tab.iconOff, selectedImage: tab.iconOn)设置它自己的tabBarItem属性,但是unselectedItemTintColor在头像上设置了一个覆盖,这是我不想要的,因为它应该按原样显示头像。

可以在每个选项卡上设置unselectedItemTintColor吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-26 19:01:40

尝试像这样使用renderingMode(.alwaysOriginal)提供图像:

代码语言:javascript
复制
tabBarItem = UITabBarItem(title: nil,
                          image: tab.iconOff?.withRenderingMode(.alwaysOriginal),
                          selectedImage: tab.iconOn?.withRenderingMode(.alwaysOriginal))
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62020562

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档