Change tab bar tint color on iOS 7
Try the below:
[[UITabBar appearance] setTintColor:[UIColor redColor]];
[[UITabBar appearance] setBarTintColor:[UIColor yellowColor]];
To tint the non active buttons, put the below code in your VC's viewDidLoad
:
UITabBarItem *tabBarItem = [yourTabBarController.tabBar.items objectAtIndex:0];
UIImage *unselectedImage = [UIImage imageNamed:@"icon-unselected"];
UIImage *selectedImage = [UIImage imageNamed:@"icon-selected"];
[tabBarItem setImage: [unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem setSelectedImage: selectedImage];
You need to do this for all the tabBarItems, and yes I know it is ugly and hope there will be cleaner way to do this.
Swift:
UITabBar.appearance().tintColor = UIColor.red
tabBarItem.image = UIImage(named: "unselected")?.withRenderingMode(.alwaysOriginal)
tabBarItem.selectedImage = UIImage(named: "selected")?.withRenderingMode(.alwaysOriginal)
Change tab bar colour in iOS 7?
If you open up your Tab Bar Controller scene in the storyboard, you should see a Tab Bar Controller with a Tab Bar object as a child object. Select the Tab Bar object and open up the Attributes Inspector. You can change the tint color by modifying the Bar Tint property right under the Style drop down.
To modify it programatically, try this:
self.tabBarController.tabBar.barTintColor = [UIColor colorWithRed:0.376 green:0.729 blue:0.318 alpha:1.000];
Change UITabBar tint colors in the More menu
To do what you need, you should use images by creating UITabBarItem for each controller and add an image and a selected image.
See Apple Documentation about UITabBarItem
Otherwise looks here, from @Aaron Brager :
- How to set UITabBarItem's unselected tint, ***including system items*** (iOS7)
- UITabBarController unselected icon image tint
Edit after seing the full code
First there is many mistakes in your project, assets should be in xcassets folder, in view didload write your code after the 'super viewDidLoad]', etc.
About your problem, in your viewDidLoad method in the FirstViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Your code start here, not before the super
[[UITabBar appearance] setTintColor:[UIColor redColor]];
// Get table view of more new viewController
UITableView *view =(UITableView*)self.tabBarController.moreNavigationController.topViewController.view;
view.tintColor = [UIColor redColor]; // Change the image color
if ([[view subviews] count]) {
for (UITableViewCell *cell in [view visibleCells]) {
cell.textLabel.textColor = [UIColor redColor]; // Change the text color
}
}
}
How to change tab bar tint for multiple tabs in iOS 7
Each "tab" is actually the tabBarItem
of one of your UIViewControllers (the children of the UITabBarController).
So look at the properties of the tabBarItem
, which is a UITabBarItem. Notice that there is a selectedImage
, different from the image
(inherited from UIBarItem). So give each tab bar item an image
and a selectedImage
, and give that selectedImage
the color characteristics you want (and make sure that you derive from it an image whose rendering mode is UIImageRenderingModeAlwaysOriginal
so that your color is used, and not, as you say, the tint color).
Tab bar item tint color
To do this:: follow a simple approach..
Change tintColor as you want
Add a new set of images for unselected items and render them in original mode.
For more info, read through this link
Changing color of the active whole section in tab bar - iOS 7
One way to accomplish this would be following these steps:
Set the background color for the whole tab bar:
tabBar.backgroundColor = [UIColor grayColor];
Have your tab icon images be the color you want them to be (white). Then set up each tab like this:
UIImage *tabImage = [UIImage imageNamed:@"my_image"];
// make sure the original color of the image is used, rather than templating it
tabImage = [tabImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
myViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"title" image:tabImage tag:0];Set the
tintColor
of the tab bar to white also so that the selected tab won't change colors:tabBar.tintColor = [UIColor whiteColor];
Set the
selectionIndicatorImage
to get a blue background on the selected tab. You'll need to create an image either programmatically or by importing it.
iOS: Tabbar Tint Color
There is a known issue with selectedImageTintColor in iOS 7. Last I checked this has yet to be resolved. So remove -
tabBarVC.tabBarController.tabBar.selectedImageTintColor = [STColorUtils globalTintColor];
Also you want to use the UITabBar's appearance so replace
[[UIView appearance] setTintColor:[ColorUtils globalTintColor]];
with
[[UITabBar appearance] setTintColor:[ColorUtils globalTintColor]];
Changing tab bar item image and text color iOS
From UITabBarItem class docs:
By default, the actual unselected and selected images are
automatically created from the alpha values in the source images. To
prevent system coloring, provide images with
UIImageRenderingModeAlwaysOriginal.
The clue is not whether you use UIImageRenderingModeAlwaysOriginal, the important thing is when to use it.
To prevent the grey color for unselected items, you will just need to prevent the system colouring for the unselected image. Here is how to do this:
var firstViewController:UIViewController = UIViewController()
// The following statement is what you need
var customTabBarItem:UITabBarItem = UITabBarItem(title: nil, image: UIImage(named: "YOUR_IMAGE_NAME")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), selectedImage: UIImage(named: "YOUR_IMAGE_NAME"))
firstViewController.tabBarItem = customTabBarItem
As you can see, I asked iOS to apply the original color (white, yellow, red, whatever) of the image ONLY for the UNSELECTED state, and leave the image as it is for the SELECTED state.
Also, you may need to add a tint color for the tab bar in order to apply a different color for the SELECTED state (instead of the default iOS blue color). As per your screenshot above, you are applying white color for the selected state:
self.tabBar.tintColor = UIColor.whiteColor()
EDIT:
How can I change the text and icon colors for tabBarItems in iOS 7?
There are two things you need to do for this:
1) If you want to customize the TabBar itself, you need to set the barTintColor for the tabBarController:
// this will generate a black tab bar
tabBarController.tabBar.barTintColor = [UIColor blackColor];
// this will give selected icons and text your apps tint color
tabBarController.tabBar.tintColor = appTintColor; // appTintColor is a UIColor *
2) Set the tabBarItem text appearance for each state that you want to override:
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : appTintColor
} forState:UIControlStateSelected];
// doing this results in an easier to read unselected state then the default iOS 7 one
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1]
} forState:UIControlStateNormal];
Related Topics
Change the Root View of Uihostingcontroller in Swiftui
How to Remove Border from Segmented Control
What Is Difference Between Urlwithstring and Fileurlwithpath of Nsurl
How to Properly Group a List Fetched from Coredata by Date
Nsoperationqueue Serial Fifo Queue
Corebluetooth: What Is the Lifetime of Unique Uuids
Ckquery from Private Zone Returns Only First 100 Ckrecords from in Cloudkit
Apple Llvm 6.0 Error: Clang Failed with Exit Code -1
iPhone Storage in Tmp Directory
Simple Low-Latency Audio Playback in iOS Swift
Invalid Image Path - No Image Found at the Path. Cfbundleicons Xcode 5
How to Execute Some Code After a Segue Is Done
iPhone Uibutton - Image Position
How to Use Dark Mode in Simulator iOS 13
What Values Should I Use for Cfbundleversion and Cfbundleshortversionstring
Xcode 10B5 - Duplicate Symbol Linker Error, Can't Compile with Crashlytics