【问题标题】:Changing the unselected color of a UITabBar Item iOS 9更改 UITabBar 项 iOS 9 的未选择颜色
【发布时间】:2016-02-25 22:15:41
【问题描述】:
override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.'
        UITabBar.appearance().tintColor = UIColor.whiteColor()
        UITabBar.appearance().selectedImageTintColor = UIColor.redColor()
    } //method is in TabBarViewController

我希望未选择的颜色为白色,选择的颜色为红色。 selectedImageTintColor 属性在 iOS 9 中已弃用,我想知道如何才能更改未选择的图像颜色?此外,我可以通过将标签栏键路径的颜色属性更改为红色来将故事板中选定的图像色调更改为红色。我想知道是否有办法改变情节提要中未选择和选择的颜色?

【问题讨论】:

    标签: colors storyboard uitabbarcontroller ios9 uitabbaritem


    【解决方案1】:

    我在 viewDidLoad 方法中使用了这种平静的代码:

    self.tabBar.tintColor = UIColor.whiteColor()
    

    【讨论】:

    • 抱歉,我的描述不清楚。我想要未选中的白色和选中的红色。当我将色调颜色设置为白色时(与您的代码或变体一样),它选择为红色,但未选择为白色,
    • 我结合 UIImage imageWithRenderingMode 方法解决了一个类似的问题。就像这样:myImage.imageWithRenderingMode(.AlwaysOriginal)
    【解决方案2】:

    确保您的原始图像显示为白色。然后你只需告诉TabBarItem 将未选中的图像渲染为.AlwaysOriginal 并在其上设置selectedImage,如下所示:

    let tabBarImage = UIImage(named: "icon-tab-name")
    let tabBarItem = UITabBarItem(title: "Title", image: tabBarImage?.imageWithRenderingMode(.AlwaysOriginal), selectedImage: tabBarImage)
    

    然后有

    UITabBar.appearance().tintColor = UIColor.redColor()
    

    这样您将有一个未选中的白色状态和一个选中的红色状态。

    【讨论】:

      【解决方案3】:

      如果您想在 IOS 10 中更改所有这些,请在 appDelegate 中执行类似的操作。这会将所有未选中的变为黑色。

      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
          // Override point for customization after application launch.
      
          UITabBar.appearance().unselectedItemTintColor = UIColor(displayP3Red: 0, green: 0, blue: 0, alpha: 1)
      
          return true
      }
      

      【讨论】:

        猜你喜欢
        • 2012-07-15
        • 2010-10-21
        • 2014-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多