I already know how to set tabBar's "barTintColor". What I want to know is how to set a specific color to selected tabBar(Like in the pic the tabBar which is selected is having dark pink color). Just like that.Thanks in advance :)
-
possible duplicate of [How to properly customize UITabBar and UITabBarItem on iOS 7 and iOS 8?](http://stackoverflow.com/questions/27144220/how-to-properly-customize-uitabbar-and-uitabbaritem-on-ios-7-and-ios-8) – Satachito May 02 '15 at 04:07
-
are you looking for an option to make a custom uicolor like: 1 let myColor = UIColor(red: 0.5, green: 0.2, blue: 0.1, alpha: 1) ? – gutenmorgenuhu May 02 '15 at 05:18
-
No. What I am looking for is how to change the background color of tabbar item in selected state as shown in pic – Rahul Sonvane May 02 '15 at 05:22
-
@Satachito thanx for the link you provided. It partially solved my problem on text color and I've updated my question. But still I'm not getting the solution for selected tabBar color – Rahul Sonvane May 02 '15 at 05:25
-
I think your answer is sublassing UITabBarViewController as described here: [How to change UITabBar Selection color](http://stackoverflow.com/questions/790746/how-to-change-uitabbar-selection-color/18996564#18996564) – gutenmorgenuhu May 02 '15 at 05:41
-
@gutenmorgenuhu I am looking for an answer in "Swift" not Objective-C – Rahul Sonvane May 02 '15 at 06:01
-
the commands are the same. just get rid of the [] syntax. – gutenmorgenuhu May 02 '15 at 06:26
-
No kidding. Any iOS developer who doesn't take the time to get at least somewhere familiar with both Objective-C and Swift is just making their life harder. The frameworks are identical... the syntax is slightly different... if you can read Objective-C, you could have your solution quicker than posting a Swift question and demanding someone give you a Swift answer... – nhgrif May 02 '15 at 12:55
-
@nhgrif I am at beginner stage. just 4 months into it. I might not be as skilled as you are. Btw I have read somewhere that the feature I'm looking for has been deprecated , though m not sure. If you are so good with objective-c and swift both. Would have been better if you would have given the solution along with your comment. – Rahul Sonvane May 03 '15 at 04:06
-
Possible duplicate of [Set background color of active tab bar item in Swift](http://stackoverflow.com/questions/29045147/set-background-color-of-active-tab-bar-item-in-swift) – Sourabh Sharma Oct 15 '15 at 06:53
-
isn't it dupe? http://stackoverflow.com/questions/790746/how-to-change-uitabbar-selection-color?noredirect=1&lq=1 – Cruz May 04 '17 at 16:17
1 Answers
Change the tintColor (that's all you are allowed to do)
Make a subclass of UITabBarController, set it as the class of your UITabBarViewController:
class myOwnTBC: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
self.tabBar.tintColor = .blueColor()
}
}
After more research following your comment:
I do believe, Apple does not want a developer to change the backgroundcolor of the UITabBar. Please see Apple's Interface Guidelines concerning the TabBar. I quote from it:
A tab bar: Is translucent
I tried subclassing UITabBarItem and manipulate the background, which gave me the following Exception:
Directly modifying a tab bar managed by a tab bar Controller is not allowed
Solution?! You won't like it, but if you want to use a UITabBarController, you have to stick with the translucent preset.
Workaround? The only workaround I can think of at the Moment is: Create your own navigation using your own UIView-Subclass. This will violate the Interface Guidelines anyways, but you can reach your Goal.

- 2,312
- 1
- 19
- 33
-
The code which you have mentioned will change the image color of tabBar(In my case I've set it to white). So it's not the solution m looking for. – Rahul Sonvane May 04 '15 at 04:29
-
I added information to my answer, although you might not like it :) – gutenmorgenuhu May 04 '15 at 07:17
-
1Thank you so much for giving so much time to it and giving some valuable information to me.. thanx :) – Rahul Sonvane May 04 '15 at 08:59