To add a tab, first drag a new View Controller object to the storybard. Next control-drag from the tab bar controller to new view controller and select view controllers under Relationship Segue . Your tab bar controller will update with a new tab.
Implement a view controller that can hold some other view controllers. Show one of those view controllers. Show a tab bar at the bottom of the screen over the shown view controller. Switch between the various view controllers when the user taps on a tab bar button.
Add Runtime Color attribute named "tintColor" from StoryBoard. This is working(for Xcode 8 and above).
if you want unselected color.. you can add unselectedItemTintColor
too.
This elegant solution works great on SWIFT 3.0, SWIFT 4.2 and SWIFT 5.1:
On the Storyboard:
Edit: Working with Xcode 8/10, for iOS 10/12 and above.
In Swift, using xcode 7 (and later), you can add the following to your AppDelegate.swift file:
UITabBar.appearance().tintColor = UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255.0, alpha: 1.0)
This is the what the complete method looks like:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// I added this line
UITabBar.appearance().tintColor = UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255.0, alpha: 1.0)
return true
}
In the example above my item will be white. The "/255.0" is needed because it expects a value from 0 to 1. For white, I could have just used 1. But for other color you'll probably be using RGB values.
On Xcode8
I have changed the ImageTint
from the storyboard and it works well.
The result:
Swift 3 | Xcode 10
If you want to make all tab bar items the same color (selected & unselected)...
Step 1
Make sure your image assets are setup to Render As = Template Image. This allows them to inherit color.
Step 2
Use the storyboard editor to change your tab bar settings as follows:
Step 3
Steps 1 & 2 will change the color for the selected icon. If you still want to change the color of the unselected items, you need to do it in code. I haven't found a way to do it via the storyboard editor.
Create a custom tab bar controller class...
// TabBarController.swift
class TabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
// make unselected icons white
self.tabBar.unselectedItemTintColor = UIColor.white
}
}
... and assign the custom class to your tab bar scene controller.
If you figure out how to change the unselected icon color via the storyboard editor please let me know. Thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With