【问题标题】:IOS - tab bar item image modificationsIOS——标签栏项目图片修改
【发布时间】:2016-09-24 13:22:03
【问题描述】:

我想将标签栏项目图像的默认颜色更改为图像的原始颜色(黑色),而不是未选中时的灰色。

我还想在选择标签栏项目图像后将其更改为填充版本。

最后一件事是位置..它似乎期望它下面的文本所以它没有居中,我如何垂直居中并可能使其更小?

我目前是这样设置的:

   let profileNavController = UINavigationController(rootViewController: profileController)
        profileNavController.tabBarItem.image = UIImage(named: "icon_tab_user")

这是选中和未选中的样子:

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    从苹果我们知道,

    默认情况下,实际未选择和选择的图像是根据源图像中的 alpha 值自动创建的。为防止系统着色,请为图像提供 UIImageRenderingModeAlwaysOriginal。

    看看这里。
    Changing tab bar item image and text color iOS

    【讨论】:

      【解决方案2】:

      我可以更改突出显示和未突出显示的图像以及位置:

      let profileNavController = UINavigationController(rootViewController: profileController)
              let profileTabBarItem  = UITabBarItem(title: nil, image: UIImage(named: "icon_tab_user")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal), selectedImage: UIImage(named: "icon_tab_user_highlighted"))
              profileTabBarItem.imageInsets = UIEdgeInsetsMake(5.5, 0, -5.5, 0)
              profileNavController.tabBarItem = profileTabBarItem
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-09-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-11
        • 2012-02-27
        • 1970-01-01
        相关资源
        最近更新 更多