How to change default ViewController of UITabBarController - ios

I create basic TabBarController with 2 ViewControllers.
It worked but it have bug and i want something about it.
Problem1.
When I run (default ViewController is FirstViewController) name of SecondViewController in TabBar is not appear.
I want following this picture.
Problem2.
In my code default view is FirstViewController.
If I want to set default view is SecondViewController
by Same Tab Bar(FirstView Tab : Left ,and SecondView Tab : Right)
following this picture. How to resolve it.
This is my example code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
FirstViewController *firstVC = [[FirstViewController alloc] init];
UINavigationController *firstNVC = [[UINavigationController alloc] initWithRootViewController:firstVC];
firstNVC.navigationBar.barStyle = UIBarStyleBlack;
SecondViewController *secondVC = [[SecondViewController alloc] init];
UINavigationController *secondNVC = [[UINavigationController alloc] initWithRootViewController:secondVC];
secondNVC.navigationBar.barStyle = UIBarStyleBlack;
UITabBarController *tabController = [[UITabBarController alloc]init];
tabController.navigationItem.hidesBackButton = NO;
tabController.viewControllers = [NSArray arrayWithObjects:firstNVC, secondNVC, nil];
tabController.navigationController.navigationBarHidden = NO;
self.window.rootViewController = tabController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Thank You. ^^

UIViewController *viewController1 = [[[viewController1 alloc] initWithNibName:#"viewController1" bundle:nil] autorelease];
UIViewController *viewController2 = [[[viewController2 alloc] initWithNibName:#"viewController2" bundle:nil] autorelease];
UIViewController *viewController3 = [[[viewController3 alloc] initWithNibName:#"viewController3" bundle:nil] autorelease];
navControl1=[[UINavigationController alloc]initWithRootViewController:viewController1];
navControl2=[[UINavigationController alloc]initWithRootViewController:viewController2];
navControl3=[[UINavigationController alloc]initWithRootViewController:viewController3];
navControl1.navigationBar.tintColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
navControl2.navigationBar.tintColor=[UIColor blackColor];
navControl3.navigationBar.tintColor=[UIColor blackColor];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.delegate=self;
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navControl2,navControl1,navControl3, nil ];
[[[[self.tabBarController tabBar] items] objectAtIndex:2] setFinishedSelectedImage:[UIImage imageNamed:#""] withFinishedUnselectedImage:[UIImage imageNamed:#""]];
[[[[self.tabBarController tabBar] items] objectAtIndex:0] setTitle:#"1"];
[[[[self.tabBarController tabBar] items] objectAtIndex:0] setImage:[UIImage imageNamed:#"tab2.png"]];
[[[[self.tabBarController tabBar] items] objectAtIndex:1] setTitle:#"2"];
[[[[self.tabBarController tabBar] items] objectAtIndex:1] setImage:[UIImage imageNamed:#"tab11.png"]];
[[[[self.tabBarController tabBar] items] objectAtIndex:2] setTitle:#"3"];
[[[[self.tabBarController tabBar] items] objectAtIndex:2] setImage:[UIImage imageNamed:#"tab5.png"]];
[self.tabBarController.tabBar setSelectionIndicatorImage:[UIImage imageNamed:#"trans.png"]];
UIImage* tabBarBackground = [UIImage imageNamed:#""];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"trans.png"]];

Problem2. If I want to
set default view is SecondViewController by Same Tab Bar(FirstView Tab
: Left ,and SecondView Tab : Right). How to
resolve it.
Solution:
[self.tabBarController setSelectedIndex:1];

Problem 1:
try to set a title for the view controllers.
Problem 2:
You just set selected index of the tabBarController to 1, that should do it.

Problem1
You haven't set tabbarItem for each navigation controller, I think you should set up a UITabBarItem with title first, then assign it to tabbarItem property to navigation controller.
Problem2
Just as #Kumar says.

Related

when i am adding in UITabBar background image then height increase automatically

I am adding UITabBar controller, But problem is that when i am set background image its Black space from bottom and when i remove the background image its works fine .
I am adding in app delegate
-(void)gotoLoginStoryBoard
{
UIStoryboard *storyboard ;
storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *login = [storyboard instantiateInitialViewController];
recentsViewController = [[RecentsViewController alloc]
initWithStyle:UITableViewStylePlain];
recentsViewController.phoneCallDelegate = self;
UINavigationController *recentsViewCtrl = [[[UINavigationController alloc]
initWithRootViewController:
recentsViewController]
autorelease];
recentsViewCtrl.navigationBar.barStyle = UIBarStyleBlackOpaque;
[recentsViewController release];
phoneViewController = [[[PhoneViewController alloc]
initWithNibName:nil bundle:nil] autorelease];
phoneViewController.phoneCallDelegate = self;
ContactViewController *contactsViewCtrl = [[[ContactViewController alloc]
init] autorelease];
contactsViewCtrl.phoneCallDelegate = self;
VoicemailController *voicemailController = [[VoicemailController alloc]
initWithStyle:UITableViewStyleGrouped];
voicemailController.phoneCallDelegate = self;
UINavigationController *voicemailNavCtrl = [[[UINavigationController alloc]
initWithRootViewController:
voicemailController]
autorelease];
voicemailNavCtrl.navigationBar.barStyle = UIBarStyleBlackOpaque;
[voicemailController release];
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:
/*favoritesViewCtrl,*/ login,
phoneViewController, contactsViewCtrl, nil];
tabBarController.selectedIndex = 0;
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:#"tabbarimage.png"]];
[[[self.tabBarController.viewControllers objectAtIndex:1] tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:#"fill3Copy.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"pathCopy4.png"]];
[[[self.tabBarController.viewControllers objectAtIndex:1] tabBarItem]setTitle:#"Contact"];
[[[self.tabBarController.viewControllers objectAtIndex:2] tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:#"fill3Copy3.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"pathCopy5.png"]];
[[[self.tabBarController.viewControllers objectAtIndex:2] tabBarItem]setTitle:#"Group"];
[[UITabBar appearance] setBackgroundColor:[UIColor blackColor ]];
[self.window setRootViewController:tabBarController];
}
First of All check your imagesize.
from apple documentation the maximum size of a picture on the TabBar
are 30x30 (60x60 for the retina display).
I think it's not possible to take the entire height of the TabBar without strech the image like UIimageview . so, according to me the best solution is to center the image in the TabBar using imageInset.
tabBarItem.imageInsets = UIEdgeInsetsMake(0, -10, -6, -10);
OR
tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
Set Imageinsect till image fit to tabbar controller.
For More Detail Check Apple Document below link.
Icon and Image Sizes
I hope it will helpful for you.
i was missing this line in appellate.
MelpHomeViewController *melpHome = (MelpHomeViewController *)[storyboard instantiateViewControllerWithIdentifier:#"homeController"];

addSubview to rootViewController

I updated my version of XCode and now I get the following error:
*application windows are expected to have a root view controller*
I read that the error is because I have no RootViewController assigned .
The problem is that I have multiple subviews and any is a main view.
Example:
// Add the view controller's view to the window and display.
[window addSubview:infoTabViewController.view];
[window addSubview:shareTabViewController.view];
[window addSubview:tabViewController.view];
[window addSubview:mainTabViewController.view];
How you could assign these subviews to a RootViewController?
Thanks.
Firstly you Write in appdelegate.m to set root view controller
- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.logviewController = [[LoginViewController alloc]init];
self.navigationController = [[UINavigationController alloc]initWithRootViewController:self.logviewController];
[self.window setRootViewController: self.navigationController];
[self.window makeKeyAndVisible];
return YES;
}
after that add tabbar controller and write code in view did load
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationItem.leftBarButtonItem=nil;
self.navigationItem.hidesBackButton=YES;
self.view.backgroundColor = [UIColor whiteColor];
self.title = #"Welcome To MyConnect";
_friendviewcontroller = [FriendsViewController new];
_homeviewcontroller = [HomePageViewController new];
_notifviewcontroller = [NotificationViewController new];
_messageviewcontroller = [MessagesViewController new];
self.tabbarcontroller = [[UITabBarController alloc]init];
self.viewControllers = [NSArray arrayWithObjects:_homeviewcontroller,_messageviewcontroller,_friendviewcontroller,_notifviewcontroller, nil];
//UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [self.tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [self.tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [self.tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [self.tabBar.items objectAtIndex:3];
[item0 setFinishedSelectedImage:[UIImage imageNamed:#"blue-home-icon.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"home_2.png"]];
[item1 setFinishedSelectedImage:[UIImage imageNamed:#"email-icon-env.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"message_2.png"]];
[item2 setFinishedSelectedImage:[UIImage imageNamed:#"friendreq_icon.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"friendreq_2.jpg"]];
[item3 setFinishedSelectedImage:[UIImage imageNamed:#"notification_icon.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"bell-512.png"]];
UIImage *img1=[UIImage imageNamed:#"menu-2-128.png"];
CGRect frameimg1 = CGRectMake(340, 0, 35,35);
UIButton *signOut=[[UIButton alloc]initWithFrame:frameimg1];
[signOut setBackgroundImage:img1 forState:UIControlStateNormal];
[signOut addTarget:self action:#selector(collectionmenutwo:)forControlEvents:UIControlEventTouchUpInside];
[signOut setShowsTouchWhenHighlighted:YES];
UIBarButtonItem *barButton=[[UIBarButtonItem alloc]initWithCustomView:signOut];
self.navigationItem.rightBarButtonItem=barButton;
item0.title = #"Home";
item1.title = #"Messages";
item2.title = #"Friends Requests";
item3.title = #"Notification";
}
take a UITabBarController and make this rootViewController.
and add all of your subview on this TabBarController.
code sample
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
UITabBarController *tabBarController = [[UITabBarController alloc]init];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
FirstViewController *firstViewController = [storyboard instantiateViewControllerWithIdentifier:#"FirstViewController"];
SecondViewController *secondViewController = [storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
tabBarController.viewControllers = #[firstViewController,secondViewController];
[self.window setRootViewController: tabBarController];
[self.window makeKeyAndVisible];
But don't add NavigationController

UINavigation with UITabbar not working

I'm trying to change views within an app I am editing the code for. But the navigation bar doesn't seem to update in specific instances when presenting a new viewcontroller. Right now the behavior looks like this:
I navigate to a tableviewcontroller by clicking on a tab in the tabbar,
then I navigate to a viewcontroller from this tableviewcontroller using:
settingsController = [SettingsController create];
[self.navigationController pushViewController: settingsController animated: YES];
which I believe calls this code:
+(id)create
{
SettingsController*settings = [[SettingsController alloc] init];
NSBundle*bundle = [NSBundle bundleForClass: [SettingsController class]];
[bundle loadNibNamed: #"SettingsController" owner: settings options: NULL];
settings.view.frame = CGRectMake(0, 0, 320, 411);
settings.title = #"Settings";
return settings;
}
Then from there I navigate to another view controller using:
SearchViewController*searchView;
searchView = [[SearchViewController alloc] initWithNibName:#"SearchView" bundle: [NSBundle mainBundle]];
[self presentViewController:searchView animated:YES completion:nil];
and this is where the behavior starts getting buggy, the navigation bar doesnt update to the change in the view controller. I didn't write this code but it has been giving me a headache trying to clean it up.
If you are using a navigationController then you shouldn't call
[self presentViewController:searchView animated:YES completion:nil];.
You should use
[self.navigationController pushViewController:searchView animated:YES];
Also, it would be better to use the standard in-built function to initialize a new view controller.
SettingsController*settings = [[SettingsController alloc] initWithNibName:#"SettingsController" bundle:nil];
[self.navigationController pushViewController:settings animated:YES];
and then use the default method in the view controller.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = #"Settings";
//other view changes.
}
return self;
}
See this example for the way of initializing tabbarcontroller with navigation controller
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *viewController1, *viewController2,*viewController3;
viewController1 = [[ViewController alloc] init];
viewController2 = [[FormStatusViewController alloc] initWithNibName:#"FormStatusViewController" bundle:nil];
viewController3 = [[DocumentsViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController *nav1 =[[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController *nav2 =[[UINavigationController alloc] initWithRootViewController:viewController3];
nav.navigationBarHidden=YES;
nav1.navigationBarHidden=YES;
nav2.navigationBarHidden=YES;
NSArray *viewsArray = [[NSArray alloc] initWithObjects:nav,nav1,nav2, nil];
self.formTabBar= [[UITabBarController alloc] init];
[self.formTabBar setViewControllers:viewsArray];
UITabBar *tabBar = self.formTabBar.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
tabBarItem1.title = #"FORM";
tabBarItem2.title = #"STATUS";
tabBarItem3.title = #"DOCUMENTS";
UIImage *tabBackground = [[UIImage imageNamed:#"tab_bg.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:#"form.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"form_h.png"]];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:#"status.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"status_h.png"]];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:#"documents.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"documents_h.png"]];
} else {
tabBarItem1.selectedImage = [[UIImage imageNamed:#"form_h.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem1.image = [[UIImage imageNamed:#"form.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem2.selectedImage = [[UIImage imageNamed:#"status_h.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem2.image = [[UIImage imageNamed:#"status.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem3.selectedImage = [[UIImage imageNamed:#"documents_h.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem3.image = [[UIImage imageNamed:#"documents.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
}
[[UITabBar appearance] setSelectionIndicatorImage:
[UIImage imageNamed:#"tab_select_indicator.png"]];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
nil] forState:UIControlStateHighlighted];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.formTabBar;
[self.window makeKeyAndVisible];
return YES;
}
Now in your view controller suppose the firstviewcontroller in first tab you want to navigate to another view controller in that tab then use below code
SearchViewcontroller *searchView =[[SearchViewcontroller alloc]init];
[self.navigationController pushViewController:searchView animated:YES];

How to Navigate from one view to another view in ios?

I have tab bar with 4 options.
In the 1st tab, I have a button. When i click this button, I have to move from one view to another view in second tab bar.
the code I am currently using is (where shipVC is the second tab's viewController):
[shipVC.navigationController pushViewController:cartVC animated:NO];
So basically, When the button in the 1st tab viewController is pressed, I want to move from 'X' view to 'Y' view in the 2nd tab's viewController
One quick way to do this is by using NSNotificationCenter to post a notification when the button in the first tab's viewController is pressed.
Steps:
in the 2nd tab's viewController's -viewDidLoad method:
Add a notification observer and set a target selector method to it
in the 1st tab's viewController's button method:
Post the notification
Example:
Your 2nd tab's viewController class:
-(void)viewDidLoad {
[super viewDidLoad];
[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(doTheNavigation)
name:#"AnyNameYouWantForNotification"
object:nil];
}
-(void)doTheNavigation {
[self.navigationController pushViewController:cartVC animated:NO];
//WARNING: don't just push, put a check or else repeated click on the
//button in the 1st tab will push cartVC again and again.
//This will not only warrant a crash but look very ugly
}
Button method in the 1st tab's viewController class:
-(IBAction)someBtnClick:(UIButton *)sender {
//...
//you can use this to post a notification from anywhere now
[[NSNotificationCenter defaultCenter] postNotificationName:#"AnyNameYouWantForNotification"
object:nil];
//...
}
So...
When the button in the 1st tab is clicked, the button action (that I named someBtnClick) will post a notification with the name AnyNameYouWantForNotification
The 2nd tab (should be already loaded and ready) will be listening for a notification that has AnyNameYouWantForNotification as it's name.
When this notification is received, it will execute the linked selector method (that I named doTheNavigation)
check my answer
-(void)settabbar{
UIViewController *viewController1 = [[[viewController1 alloc] initWithNibName:#"viewController1" bundle:nil] autorelease];
UIViewController *viewController2 = [[[viewController2 alloc] initWithNibName:#"viewController2" bundle:nil] autorelease];
UIViewController *viewController3 = [[[viewController3 alloc] initWithNibName:#"viewController3" bundle:nil] autorelease];
navControl1=[[UINavigationController alloc]initWithRootViewController:viewController1];
navControl2=[[UINavigationController alloc]initWithRootViewController:viewController2];
navControl3=[[UINavigationController alloc]initWithRootViewController:viewController3];
navControl1.navigationBar.tintColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
navControl2.navigationBar.tintColor=[UIColor blackColor];
navControl3.navigationBar.tintColor=[UIColor blackColor];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.delegate=self;
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navControl1,navControl2,navControl3, nil ];
[[[[self.tabBarController tabBar] items] objectAtIndex:2] setFinishedSelectedImage:[UIImage imageNamed:#""] withFinishedUnselectedImage:[UIImage imageNamed:#""]];
[[[[self.tabBarController tabBar] items] objectAtIndex:0] setTitle:#"view1"];
[[[[self.tabBarController tabBar] items] objectAtIndex:0] setImage:[UIImage imageNamed:#"tab2.png"]];
[[[[self.tabBarController tabBar] items] objectAtIndex:1] setTitle:#"view2"];
[[[[self.tabBarController tabBar] items] objectAtIndex:1] setImage:[UIImage imageNamed:#"tab11.png"]];
[[[[self.tabBarController tabBar] items] objectAtIndex:2] setTitle:#"ciew3"];
[[[[self.tabBarController tabBar] items] objectAtIndex:2] setImage:[UIImage imageNamed:#"tab5.png"]];
[[[[self.tabBarController tabBar] items] objectAtIndex:3] setTitle:#"Maintain Customer"];
[[[[self.tabBarController tabBar] items] objectAtIndex:3] setImage:[UIImage imageNamed:#"tab4.png"]];
[self.tabBarController.tabBar setSelectionIndicatorImage:[UIImage imageNamed:#"trans.png"]];
UIImage* tabBarBackground = [UIImage imageNamed:#""];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"trans.png"]];
}
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController*)viewController{
NSLog(#"select : %d",tabBarController.tabBar.selectedItem.tag);
if(self.tabBarController.tabBar.selectedItem.tag==0){
[[self.tabBarController.viewControllers objectAtIndex:0] popViewControllerAnimated:YES];
}else if(self.tabBarController.tabBar.selectedItem.tag==1){
[[self.tabBarController.viewControllers objectAtIndex:1] popViewControllerAnimated:YES];
}else if(self.tabBarController.tabBar.selectedItem.tag==2){
[[self.tabBarController.viewControllers objectAtIndex:2] popViewControllerAnimated:YES];
}else {
[(UINavigationController*) viewController popToRootViewControllerAnimated:YES];
}
return YES;
}
You need to also make application with Naigationcontroller in your appdelegate
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
HomeViewController *homeView = [[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:homeView animated:YES];
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:homeView];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
after that your navigationbar will appear in your first viewcontroller then you can navigate.

colour icon in UITabbar item objective-c

I have a UITabbar controller with 3 item, I want to have colour icon instead of based Gary icons,
would you please give me some hint that how can I have colour icon in tababr,
Here is my code:
self.title = #"test";
self.tabBarItem = [[UITabBarItem alloc] initWithTitle:self.title image:[UIImage
imageNamed:#"test"] tag:0];
normally test is a icone with a colour picture, but in UITabbar it's just Gary,
Thanks in advance!
Use this code:
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:#"test"]
withFinishedUnselectedImage:[UIImage imageNamed:#"test"]];
You will need to build your own TabBarController. As Per the Apple docs on the matter "This class [UITabBarController] is not intended for subclassing". The docs on the UITabBarItem say that when you are supplying an image for the tab bar "The images displayed on the tab bar are derived from this image". So, whatever image you provide to the tab bar will get manipulated to make it conform to the "normal" look of a tab bar image.
So, you can build a UIViewController with some UIButtons as subviews and then manage the entire look and feel that way.
you have to create 2 images for all 3 tabs one is unselected and second is selected.
after that in your appdelegate.m file write below code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.searchArray = [[NSMutableArray alloc]init];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
viewController1 *view1 = [[[viewController1 alloc] initWithNibName:#"viewController1" bundle:nil] autorelease];
view1.tabBarItem.image = [UIImage imageNamed:#"tab-selected-1"];
view1.tabBarItem.title = #"Title1";
viewController2 *view2 = [[[viewController2 alloc] initWithNibName:#"viewController2" bundle:nil] autorelease];
view2.tabBarItem.image = [UIImage imageNamed:#"tab-selected-2"];
view2.tabBarItem.title = #"Title2";
viewController3 *view3 = [[[viewController3 alloc] initWithNibName:#"viewController3" bundle:nil] autorelease];
view3.tabBarItem.image = [UIImage imageNamed:#"tab-selected-3"];
view3.tabBarItem.title = #"Title3";
self.tabBarController.viewControllers = [NSArray arrayWithObjects:view1, view2, view3, nil];
UITabBarItem *tabBarItem1 = [[self.tabBarController.tabBar items] objectAtIndex:0];
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:#"tab-selected-1.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"tab-unselected-1.png"]];
UITabBarItem *tabBarItem2 = [[self.tabBarController.tabBar items] objectAtIndex:1];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:#"tab-selected-2.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"tab-unselected-2.png"]];
UITabBarItem *tabBarItem3 = [[self.tabBarController.tabBar items] objectAtIndex:2];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:#"tab-selected-3.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"tab-unselected-3.png"]];
return YES;
}
try this your problem surly solved. Best Of Luck

Resources