i am using tab bar control in my app and want to use the default search icon in one of my tab. I am making the tab bar programmically but i am not able to find a property where i can specify UITabBarSystemItemSearch item which i find in apple documentation. Following is my code for tab bar
CouponsViewController *coupons = [[CouponsViewController alloc] init];
UINavigationController *couponsNavigationController = [[UINavigationController alloc] initWithRootViewController:coupons];
couponsNavigationController.tabBarItem.title = #"Coupons";
couponsNavigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1];
[coupons release];
SettingsViewController *settings = [[SettingsViewController alloc] init];
UINavigationController *settingsNavigationController = [[UINavigationController alloc] initWithRootViewController:settings];
settingsNavigationController.tabBarItem.title = #"Settings";
settingsNavigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1];
[settings release];
ProfileViewController *profile = [[ProfileViewController alloc] init];
UINavigationController *profileNavigationController = [[UINavigationController alloc] initWithRootViewController:profile];
profileNavigationController.tabBarItem.title = #"Profile";
profileNavigationController.tabBarItem.image = [UIImage imageNamed:#"profileImg.png"];
profileNavigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1];
[profile release];
[tabBarController setViewControllers:[NSArray arrayWithObjects:loyaltyNavigationController,searchNavigationController,couponsNavigationController,settingsNavigationController,profileNavigationController,nil] animated:NO];
tabBarController.delegate=self;
tabBarController.selectedIndex=0;
[window addSubview:tabBarController.view];
execute this code in your UIViewController subclass that you are putting into the tab bar. This is best done in your view controller's initializer method:
- (id) init
{
self.title = #"search";
self.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch
tag:0];
return self;
}
Related
I am unable to see NavigationBar on my TabView Controller.
I tried to add two tabs.
The class hierarchy is like below.
Please help.
ViewControllerOne : UIViewController
ViewControllerTwo : UIViewController
TabViewController : UITabBarController
ViewControllerOne *viewFirst = [[ViewControllerOne alloc]init];
ViewControllerOther *viewSecond = [[ViewControllerOther alloc]init];
[self.tabBarController.navigationController setViewControllers:#[viewFirst, viewSecond]];
[self.tabBarController.navigationController setTitle:#"TITLE TITLE"];
viewFirst.title=#"ONE";
viewFirst.tabBarItem.image = [UIImage imageNamed:#"first.png"];
viewSecond.title=#"TWO";
viewSecond.tabBarItem.image = [UIImage imageNamed:#"second.png"];
viewFirst.view.backgroundColor = [UIColor grayColor];
viewSecond.view.backgroundColor = [UIColor whiteColor];
self.viewControllers = [NSArray arrayWithObjects:viewFirst, viewSecond, nil];
I'm not sure what "self" is, but it looks like it is just a random view controller. More context on that would be good, but I'll try to throw some thoughts.
It looks like you're trying to set viewFirst and viewSecond as a navigation stack, rather then the two different tabs. It also appears like you aren't placing those controllers within UINavigationControllers. Try something more along these lines:
ViewControllerOne *one = [[ViewControllerOne alloc] init];
one.title = #"ONE";
one.tabBarItem.image = [UIImage imageNamed:#"first.png"];
one.view.backgroundColor = [UIColor grayColor];
UINavigationController *navOne = [[UINavigationController alloc] initWithRootViewController:one];
ViewControllerTwo *two = [[ViewControllerOne alloc] init];
two.title = #"SECOND";
two.tabBarItem.image = [UIImage imageNamed:#"second.png"];
two.view.backgroundColor = [UIColor whiteColor];
UINavigationController *navTwo = [[UINavigationController alloc] initWithRootViewController:two];
TabViewController *tabController = [[TabViewController alloc] init];
[tabController setViewControllers:#[navOne, navTwo] animated:NO];
Make sure that the tabController is the key UIWindow's root view controller.
I want to create a tabBar in my app but only in a detailView not in the AppDelegate. I am searching how to do this in google but everything what I have figured out is in AppDelegate.m
I am trying to do something like this. This shows me a Tab bar with two buttons(without names) but I want to go from one FirstViewController with tabBar, to one of the two items SecondViewController or ThirdViewController with a navigationBar with one backItemButton for get back to the FirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupTabBar];
}
- (void) setupTabBar {
tabBars = [[UITabBarController alloc] init];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:4];
YPProfileViewController *profile = [[YPProfileViewController alloc] init];
YPProfileViewController *profile2 = [[YPProfileViewController alloc] init];
[localViewControllersArray addObject:profile];
[localViewControllersArray addObject:profile2];
tabBars.tabBarItem = profile2;
tabBars.viewControllers = localViewControllersArray;
tabBars.view.autoresizingMask==(UIViewAutoresizingFlexibleHeight);
[self.view addSubview:tabBars.view];
}
at least this works for me.
UIViewController *vc1 = [[UIViewController alloc] init];
vc1.title = #"FIRST";
vc1.view.backgroundColor = [UIColor blueColor];
UIViewController *vc2 = [[UIViewController alloc] init];
vc2.title = #"SECOND";
vc2.view.backgroundColor = [UIColor redColor];
UITabBarController *tabBar = [[UITabBarController alloc] init];
tabBar.viewControllers = #[vc1,vc2];
tabBar.selectedIndex = 1;
tabBar.view.frame = CGRectMake(50, 50, 220, 320);
[tabBar willMoveToParentViewController:self];
[self.view addSubview:tabBar.view];
[self addChildViewController:tabBar];
[tabBar didMoveToParentViewController:self];
This is RegisterViewController.m part
if ([message isEqualToString:#"registerOK"]){
self.findViewController = [[FindViewController alloc] initWithNibName:nil bundle:NULL];
self.friendViewController = [[FriendViewController alloc] initWithNibName:nil bundle:NULL];
self.goViewController = [[GoViewController alloc] initWithNibName:nil bundle:NULL];
self.settingViewController = [[SettingViewController alloc] initWithNibName:nil bundle:NULL];
self.findNavigationController = [[UINavigationController alloc] initWithRootViewController:self.findViewController];
self.friendNavigationController = [[UINavigationController alloc] initWithRootViewController:self.friendViewController];
self.goNavigationController = [[UINavigationController alloc] initWithRootViewController:self.goViewController];
self.settingNavigationController = [[UINavigationController alloc] initWithRootViewController:self.settingViewController];
//[self.findNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"nav-bar-background-light.png"] forBarMetrics:UIBarMetricsDefault];
[self.findNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"nav-bar-background-light.png"] forBarMetrics:UIBarMetricsDefault];
[self.friendNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"nav-bar-background-light.png"] forBarMetrics:UIBarMetricsDefault];
[self.goNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"nav-bar-background-light.png"] forBarMetrics:UIBarMetricsDefault];
[self.settingNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"nav-bar-background-light.png"] forBarMetrics:UIBarMetricsDefault];
NSArray *allViewController = [[NSArray alloc] initWithObjects:self.findNavigationController,self.friendNavigationController,self.goNavigationController,self.settingNavigationController, nil];
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController setViewControllers:allViewController];
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[self.view addSubview:self.tabBarController.view];
[window setRootViewController:self];
}
I want to create a TabBarController in RegisterViewController. How can I do it?
In AppDelegate.m I have an if which does: if already login then create TabBarController, if not go to RegisterViewController, then if register complete I want to create TabBarController. How to do this? Thanks.
You could just show your login and register views on top of tabBarController.view by [self.tabBarController presentViewController:] or such.
Make public method in AppDelegate and create there tabbar as usual.
And call this method where you need:
[(ASAppDelegate *)[[UIApplication sharedApplication] delegate]yourMethod]
How do I integrate a UITabbarcontroller in a UIViewController class not in the app delegate? I was suppose to make a login view and after it the UITabBarController appears which was created in a UIViewController class? Can anyone suggest what needs to be done? thanks
You can still put the UITabBarController in the App Delegate, when the login is done, just tell the app delegate, and switch the them:
self.window.rootViewController=tabBarController;
if your Application is Navigation Based App, then Create TabBarController(with ViewControllers how many you want to add) and add it on Navigation Controller, like this
UITabBarController *tabBarController = [Utility configureMessagesTabBArController];
self.navigationController.navigationBarHidden=YES;
[self.navigationController pushViewController:tabBarController animated:YES];
[tabBarController release];
here is configureMessagesTabBArController Method from Utility class
+(UITabBarController *)configureMessagesTabBArController
{
UITabBarController *tabBarController = [[UITabBarController alloc]init];
AktuellesViewController *aktuelles_Controller = [[AktuellesViewController alloc]init];
TermineViewController *termine_Controller = [[TermineViewController alloc]init];
TopTenViewController *topTen_Controller = [[TopTenViewController alloc]init];
MediathekViewController *mediathek_Controller = [[MediathekViewController alloc]init];
KontaktViewController *kontakt_Controller = [[KontaktViewController alloc] init];
UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:aktuelles_Controller];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:termine_Controller];
UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:topTen_Controller];
UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:mediathek_Controller];
UINavigationController *nav5 = [[UINavigationController alloc]initWithRootViewController:kontakt_Controller];
nav1.navigationBar.tintColor = [UIColor blackColor];
nav2.navigationBar.tintColor = [UIColor blackColor];
nav3.navigationBar.tintColor = [UIColor blackColor];
nav4.navigationBar.tintColor = [UIColor blackColor];
nav5.navigationBar.tintColor = [UIColor blackColor];
[tabBarController setViewControllers:[[NSArray alloc]initWithObjects:nav1,nav2,nav3,nav4,nav5,nil]];
[nav1 release];
[nav2 release];
[nav3 release];
[nav4 release];
[nav5 release];
[aktuelles_Controller release];
[termine_Controller release];
[topTen_Controller release];
[mediathek_Controller release];
[kontakt_Controller release];
return tabBarController;
}
I am using tab bar controller with more than 5 tab items with color as green (ie customized) in my application. As we know 5th, 6th.. tabbar items are handled automatically by MoreViewController.
My question is
1) if I select the More Tabbar item, blue color item I did get.
2) If I switch from More Tabbar item into previous one, I also did get the items color as blue.
So, how to make the tabbar items color as green in both cases?
In apple documentation there is no solution for this. I ended with my own faked tabbar with customized buttons.
buddy you have 2 choices
1. u take 2 image for every tabbar 1st disable tile 2nd show enable time
self.window.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageNamed:#"bg.png"]]; //[UIColor blackColor];
tabBarController = [[UITabBarController alloc] init];
[tabBarController setDelegate: self];
// [tabBarController.tabBar setDelegate:self];
//tabBarController = [[UITabBarController alloc] init];
tabBarController.tabBar.tintColor=[UIColor colorWithPatternImage:[UIImage imageNamed:#"bg.png"]];
//tabBarController.tabBarItem.title=[UIColor whiteColor];
//[[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];
//[[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]];
//tabBarController.tabBar.backgroundColor = [UIColor whiteColor];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:7];
Login *home = [[Login alloc] initWithNibName:#"Login" bundle:nil];
localNavController = [[UINavigationController alloc] initWithRootViewController:home];
//localNavController.tabBarItem.image = [UIImage imageNamed:#"Central.png"];
localNavController.tabBarItem.title=#"Central";
[localViewControllersArray addObject:localNavController];
PuckDisplay *puck=[[PuckDisplay alloc]initWithNibName:#"Display" bundle:nil];
localNavController = [[UINavigationController alloc] initWithRootViewController:uck];
//localNavController.tabBarItem.image = [UIImage imageNamed:#"Display.png"];
localNavController.tabBarItem.title=#" Display";
[localViewControllersArray addObject:localNavController];
PhotoBooth *photo=[[PhotoBooth alloc]initWithNibName:#"Booth" bundle:nil];
localNavController = [[UINavigationController alloc] initWithRootViewController:photo];
//localNavController.tabBarItem.image = [UIImage imageNamed:#"Booth.png"];
localNavController.tabBarItem.title=#"Booth";
[localViewControllersArray addObject:localNavController];
More *more=[[More alloc]initWithNibName:#"More" bundle:nil];
localNavController = [[UINavigationController alloc] initWithRootViewController:more];
//localNavController.tabBarItem.image = [UIImage imageNamed:#"home.png"];
localNavController.tabBarItem.title=#"More";
[localViewControllersArray addObject:localNavController];
tabBarController.viewControllers = localViewControllersArray;
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor grayColor], UITextAttributeTextColor,
[UIColor grayColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"Helvetica" size:0.0], UITextAttributeFont, nil]
forState:UIControlStateNormal];
UITabBarItem *tabBarItem1 = [[self.tabBarController.tabBar items] objectAtIndex:0];
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:#"CentralA.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"Central.png"]];
UITabBarItem *tabBarItem2 = [[self.tabBarController.tabBar items] objectAtIndex:1];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:#"DisplayA.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"Display.png"]];
UITabBarItem *tabBarItem3 = [[self.tabBarController.tabBar items] objectAtIndex:2];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:#"BoothA.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"Booth.png"]];
UITabBarItem *tabBarItem4 = [[self.tabBarController.tabBar items] objectAtIndex:3];
[tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:#"moreA.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"more.png"]];
2. if u want only change tabbar color then change tabbar tin color
self.tabBarController.tabBar.tintColor = [UIColor colorWithRed:(157/255.0) green:(33/255.0) blue:(33/255.0) alpha:1];