0

I was able to change the active color of my tab bar using this answer

chage color inactive tab bar

my problem is i dont know how to change the inactive ones like the friends and search tab.I want to change it something like red. I have search so much and decided to ask because i coudn't find any solution.Please bear with me since im new to ios development using swift.

Community
  • 1
  • 1
jameshwart lopez
  • 2,993
  • 6
  • 35
  • 65

5 Answers5

4

I will post what I did to get what i want to achieve.This might also help biggener's like me in the future.

First I have created two images for each icon

Home Icon,Friends Icon and Search Icon each has white and green color inactive tabbar icon

Then clicking Assets.xcassets file to add New Image Set New Image Set

Making it sure that the green icons Render As is set to Original Image since this will be the inactive color icon of our tab bar.Here is a sample screen shots for the sample attribute Render As Original Image

By setting the Home Item tab bar Icon. Please Note

System Item => Custom
Selected Image => Home_w//Name of the home white icon
Title => Home
Image=> Home_g//Name of the Inactive tabbar item in my case are sets to green icons

enter image description here

finally overriding Title Color of our tab bar items in AppDelegate.swift.Please note i have used UIColor_Hex_Swift for hex UIColor.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    let color:UIColor =  UIColor(rgba: "#026a34") //UIColor(hexString:"026a34")

    UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: color], forState: .Normal)

    // then if StateSelected should be different, you should add this code
    UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor()], forState: .Selected)

    return true
}

Out put(White ones are the selected Image and green ones are the inactive image)

Home active Friends active search active

jameshwart lopez
  • 2,993
  • 6
  • 35
  • 65
1

You can set the property Render As of your tab bar images within your asset catalog directly. There you have the option to set the property to Default, Original Image and Template Image.

enter image description here

Ashish
  • 679
  • 7
  • 19
1

Since iOS 10 you can use this to change the tab item colors (you have to have the images rendering as templates):

    UITabBar.appearance().tintColor = .blue
    UITabBar.appearance().unselectedItemTintColor = .gray
odm
  • 888
  • 1
  • 14
  • 22
0

Try this

 self.tabBar.tintColor=[UIColor whiteColor];
Avijit Nagare
  • 8,482
  • 7
  • 39
  • 68
0

Possibly this is the best link you wish to search for your concrete solution.

Community
  • 1
  • 1
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57