Um using my own TabBarController
which is ElWafyatTabBarController
basically it inherits from UITabBarController
.
In ElWafyatTabBarController.m -> viewDidLoad
I've created some ViewControllers
, Then I created UINavigationController
's with rootViewController to the viewControllers
I've made in the step before.
then I've created UITabBarItem
and set it with image and title for each navigation controller which has rootViewController
to the viewControllers that I've created in the first step, and set the tabBarItem
for these navigationController
to these tabBarItem
.
The problem I found is even the title for the UITabBarItem
is shown correctly, but the image is displayed at blue Color.
FYI: I've created two images named test.png and [email protected] with dimensions 32x32 and 64x64 and I still have these issue, So any one can help ?
this is my Code:
ElWafyatTabBarController -> viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
HomeViewController *homeViewController = [[HomeViewController alloc]
initWithNibName:@"HomeViewController" bundle:nil];
NaaiViewController *naaiViewController = [[NaaiViewController alloc]
initWithNibName:@"NaaiViewController" bundle:nil];
MushatraViewController *mushatraViewController = [[MushatraViewController alloc]
initWithNibName:@"MushatraViewController" bundle:nil];
TakremViewController *takremViewController = [[TakremViewController alloc]
initWithNibName:@"TakremViewController" bundle:nil]
UINavigationController *homeNavC = [[UINavigationController alloc]initWithRootViewController:homeViewController];
UINavigationController *naaiNavC = [[UINavigationController alloc]initWithRootViewController:naaiViewController];
UINavigationController *mushatraNavC = [[UINavigationController alloc]initWithRootViewController:mushatraViewController];
UINavigationController *takremNavC = [[UINavigationController alloc]initWithRootViewController:takremViewController];
// Setup Controllers for Tab Bar. (first level).
// [homeNavC.tabBarItem setTitle:@"الرئيسية"];
// [naaiNavC.tabBarItem setTitle:@"نعي"];
// [mushatraNavC.tabBarItem setTitle:@"مشاطرة"];
// [takremNavC.tabBarItem setTitle:@"تكريم"];
homeNavC.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
naaiNavC.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
mushatraNavC.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
takremNavC.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
homeNavC.navigationBar.barStyle = UIBarStyleBlack;
naaiNavC.navigationBar.barStyle = UIBarStyleBlack;
mushatraNavC.navigationBar.barStyle = UIBarStyleBlack;
takremNavC.navigationBar.barStyle = UIBarStyleBlack;
UITabBarItem* tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Colors" image:[UIImage imageNamed:@"test.png"] tag:9];
homeNavC.tabBarItem = tabBarItem;
myViewControllers = [ NSArray arrayWithObjects:takremNavC, mushatraNavC, naaiNavC, homeNavC,nil];
[self setViewControllers:myViewControllers animated:YES];
[self.tabBarController setSelectedIndex:3];
[self setSelectedIndex:3];
}
and these the output:
If you want to see your image, you need to set the image's rendering mode to UIImageRenderingModeAlwaysOriginal
, otherwise the image is displayed as a template image. You should read the documentation on tab bars, it has this statement:
Tab Bar Item Icons
Each item in a tab bar can have a custom selected image and unselected image. You can specify these images when you initialize a tab bar item using the initWithTitle:image:selectedImage: method. Note that a tab bar item image will be automatically rendered as a template image within a tab bar, unless you explicitly set its rendering mode to UIImageRenderingModeAlwaysOriginal. For more information, see Template Images.
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