简体   繁体   中英

Tab bar item tint color

In iOS 7, I been developing an app that uses the UITabBarController and I noticed that the tab bar items stay gray even tho I change the tint color of the tab bar. Is there any way to change the color of non-selected tab bar items?

To do this:: follow a simple approach..

  1. Change tintColor as you want

  2. Add a new set of images for unselected items and render them in original mode.

For more info, read through this link

要为应用程序全局设置色调颜色,您需要在应用程序delegate didFinishLaunchingWithOptions: method添加以下代码:

[[UITabBar appearance] setTintColor:[UIColor colorWithRed:13.0/255.0 green:116.0/255.0 blue:128.0/255.0 alpha:1.0]];

@shreena app的Swift 3委托全局标签栏色调设置

UITabBar.appearance().tintColor = UIColor(red: CGFloat(13.0 / 255.0), green: CGFloat(116.0 / 255.0), blue: CGFloat(128.0 / 255.0), alpha: CGFloat(1.0))

Changing the tabBar.tintColor property is the right way to do it, however to make it work we need to tell iOS to ignore color properties of the UIImage in TabBarItem . Hence write this code in your custom TabBarViewController 's viewDidLoad()

for item in self.tabBar.items ?? [] {
    item.selectedImage = item.selectedImage?.withRenderingMode(.alwaysTemplate)
    item.image = item.image?.withRenderingMode(.alwaysTemplate)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM