Customizing appearance of tabBarItems in a TabBArController - ios

In my application, I am using a UITabBarController. However, i need to customise the appearance of my UITabBarItems.
At present, my screen looks like this:
I would like to increase the distance between the tabs, and the middle tab has bigger text, due to which the tab looks very crowded. Also, i would like to add a separator between the tabs.
Here's the code:
customerCareNavController = [[UINavigationController alloc] initWithRootViewController:custCareVC];
customerCareNavController.title = #"Inquiry";
purchaseOrderNavController = [[UINavigationController alloc] initWithRootViewController:POController];
purchaseOrderNavController.title = #"Purchase Order";
accAndContactsNavController = [[UINavigationController alloc] initWithRootViewController:accAndContactsController];
accAndContactsNavController.title = #"Accounts And Contacts";
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:customerCareNavController,accAndContactsNavController,purchaseOrderNavController, nil];
[(UITabBarItem*)[tabBarController.tabBar.items objectAtIndex:0] setImage:[UIImage imageNamed:#"Customer_Service.png"]];
[(UITabBarItem*)[tabBarController.tabBar.items objectAtIndex:1] setImage:[UIImage imageNamed:#"Acc_Cont.png"]];
[(UITabBarItem*)[tabBarController.tabBar.items objectAtIndex:2] setImage:[UIImage imageNamed:#"PO.png"]];

Set tabBarItem such like
UITabBarItem* ClientSupportTabBarItem = [[UITabBarItem alloc] init];
[ClientSupportTabBarItem setFinishedSelectedImage: [UIImage imageNamed: #"btnTabItem-active.png"] withFinishedUnselectedImage: [UIImage imageNamed: #"btnTabItemNormal.png"]];
ClientSupportTabBarItem.title = #"Inquiry";
[customerCareNavController setTabBarItem: ClientSupportTabBarItem];

Related

Using a UITabBarController and a UINavigationController together

What is the best practice or good way to have with 2 tabs behave like a UINavigationController when clicking through views after the tab bar views.
Do I make a UINavigationController for each tab?
The tab bar is created like so:
// Create the tab bar text and images
AViewController *viewA = [[AViewController alloc] init];
BViewController *viewB = [[BViewController alloc] init];
UITabBarItem *tabA = [[UITabBarItem alloc] initWithTitle:#"A" image:[UIImage imageNamed:#"a.png"] tag:1];
UITabBarItem *tabB = [[UITabBarItem alloc] initWithTitle:#"B" image:[UIImage imageNamed:#"b.png"] tag:2]
viewA.tabBarItem = tabA;
viewB.tabBarItem = tabB;
NSArray* controllers = [NSArray arrayWithObjects:viewA, viewB, nil];
self.viewControllers = controllers;
For navigation you need to create UINavigationController for each like this
Updated : Try now
AViewController *viewA = [[AViewController alloc] init];
BViewController *viewB = [[BViewController alloc] init];
UINavigationController *navA = [[UINavigationController alloc]initWithRootViewController:viewA];
UINavigationController *navB = [[UINavigationController alloc]initWithRootViewController:viewA];
UITabBarItem *tabA = [[UITabBarItem alloc] initWithTitle:#"A" image:[UIImage imageNamed:#"a.png"] tag:1];
UITabBarItem *tabB = [[UITabBarItem alloc] initWithTitle:#"B" image:[UIImage imageNamed:#"b.png"] tag:2]
tabA.tabBarItem = tabA;
tabB.tabBarItem = tabB;
NSArray* controllers = [NSArray arrayWithObjects:navA, navB, nil];
self.viewControllers = controllers;
Try this

UITabBarController initially highlights all tab bar item images

I'm programmatically instantiating a UITabBarController that will manage 2 view controllers, and then setting it as the rootViewController. However when the views appear, it highlights all the tab item's images (although the text is properly highlighted). No matter what I set to the selectedIndex the images will all appear highlighted. Only when you tap on the tab bar items does it actually toggle the highlighted state on the images. What's going on here?
Code:
UITabBarController *tabController = [[UITabBarController alloc] init];
UIStoryboard *storyboard = [self storyboard];
OGVideoStreamViewController *questionsController = [storyboard instantiateViewControllerWithIdentifier:#"OGVideoStreamViewController"];
questionsController.isQuestion = YES;
OGVideoStreamViewController *answersController = [storyboard instantiateViewControllerWithIdentifier:#"OGVideoStreamViewController"];
answersController.isQuestion = NO;
OGMatchesViewController *matchesController = [[OGMatchesViewController alloc] initWithNibName:#"OGMatchesViewController" bundle:nil];
questionsController.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Questions" image:[UIImage imageNamed:#"Tab Icon - Questions"] tag:0];
answersController.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Answers" image:[UIImage imageNamed:#"Tab Icon - Answers"] tag:1];
matchesController.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Inbox" image:[UIImage imageNamed:#"Tab Icon - Inbox"] tag:2];
[tabController setViewControllers:#[questionsController, answersController, matchesController] animated:NO];
tabController.selectedViewController = questionsController;
[[UIApplication sharedApplication] keyWindow].rootViewController = tabController;
I've had the same problem and it was due to me calling:
[UIView appearance].tintColor = [UIColor colorWithRed:1.000
green:0.793
blue:0.236
alpha:1.000];
I called it in my AppDelegate, so i could change it to the following:
self.window.tintColor = [UIColor colorWithRed:1.000
green:0.793
blue:0.236
alpha:1.000];

UITabbar disappears when i push view controller

This is my app delegate:
// Initialize your five tab controllers. with each tab has its own navigation controller
HomePageView *homePageView = [[HomePageView alloc]init];
UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:homePageView];
[nav1.navigationBar setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]}];
// Set nav Bar to be completely transparent
[nav1.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav1.navigationBar.shadowImage = [UIImage new];
nav1.navigationBar.translucent = YES;
//Set Title
nav1.tabBarItem.title = #"Home";
ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:profileViewController];
// Set Title
nav2.tabBarItem.title = #"Profile";
// Set nav Bar to be completely transparent
[nav2.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav2.navigationBar.shadowImage = [UIImage new];
nav2.navigationBar.translucent = YES;
FeedViewController *feedViewController=[[FeedViewController alloc]init];
UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:feedViewController];
// Set nav Bar to be completely transparent
[nav3.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav3.navigationBar.shadowImage = [UIImage new];
nav3.navigationBar.translucent = YES;
// Set Title
nav3.tabBarItem.title = #"Feeds";
ListeningSessionViewController *listeningSessionViewController= [[ListeningSessionViewController alloc]init];
UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:listeningSessionViewController];
// Set nav Bar to be completely transparent
[nav4.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav4.navigationBar.shadowImage = [UIImage new];
nav4.navigationBar.translucent = YES;
// set Title
nav4.tabBarItem.title = #"Mussion";
RecievedViewController *recievedViewController =[[RecievedViewController alloc]init];
UINavigationController *nav5 = [[UINavigationController alloc]initWithRootViewController:recievedViewController];
// Set nav Bar to be completely transparent
[nav5.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nav5.navigationBar.shadowImage = [UIImage new];
nav5.navigationBar.translucent = YES;
// Set Title
nav5.tabBarItem.title = #"Recieved";
// Set selected tab bar background
UIImage *whiteBackground = [UIImage imageNamed:#"whiteBackground"];
[[UITabBar appearance] setSelectionIndicatorImage:whiteBackground];
self.tabC.tabBar.translucent = YES;
// initialize tabbarcontroller,set your viewcontrollers and change its color.
self.tabC = [[UITabBarController alloc]init];
NSArray* controllers = [NSArray arrayWithObjects: nav1,nav2,nav3,nav4,nav5, nil];
[self.tabC setViewControllers: controllers animated:NO];
//[_window addSubview:self.tabC.view];
[self.window setRootViewController:self.tabC];
// Show window
[self.window makeKeyAndVisible];
return YES;
}
When i push a view controller from one of the tabbar controllers eg HomePageView, The tabbar disappears:
SearchSongViewController *Search_MusicTableView = [[SearchSongViewController alloc] init];
Search_MusicTableView.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self.navigationController presentModalViewController:Search_MusicTableView animated:YES];
When i present the modal view or even push another view controller, the tabbar disappears, please why is this ? and how do i fix it, Thanks alot !

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

Toolbar + Navigation Bar + Segmented Control?

I'm trying to find a way to layout an application that includes a tab bar on the bottom, a navigation bar on the top, and a row of buttons on the navigation bar that switches views (on the first tab).
I've drawn a very rough sketch (sorry!), but I hope it illustrates the intent.
On the bottom, there are two tabs (tab1, and tab2).
When Tab1 is selected, the navigation bar will have 3 buttons that will show different views (tab1_1, tab1_2, tab1_3).
When Tab2 is selected, the navigation bar won't show any buttons, but rather some simple text.
At this point, I have the following scheme in my application delegate's didFinishLaunchingWithOptions:
UIViewController *viewController1 = [[Tab1_ViewController alloc] initWithNibName:#"Tab1_ViewController" bundle:nil];
UIViewController *viewController2 = [[Tab2_ViewController alloc] initWithNibName:#"Tab2_ViewController" bundle:nil];
tab1NavController = [[UINavigationController alloc] initWithRootViewController:viewController1];
tab2NavController = [[UINavigationController alloc] initWithRootViewController:viewController2];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:tab1NavController, tab2NavController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
I was wondering if I need to redo how I'm doing things in order to achieve the layout as in the picture.
Any help would be appreciated, thank you!
I have done this for my current project...i hope this will help you....
At first take UITabbarController at your first viewController [first sketch you have given]
For your first view use this code....
- (void)viewDidLoad {
[super viewDidLoad];
dashBoardView = [[DashboardViewController alloc] initWithNibName:#"DashboardViewController" bundle:nil];
dashBoardView.title = #"dashBoardView";
UINavigationController *mydashboarController = [[[UINavigationController alloc] initWithRootViewController:dashBoardView] autorelease];
mydashboarController.navigationBar.barStyle = UIBarStyleBlack;
[listOfViewControllers addObject:mydashboarController];
[dashBoardView release];
ordersView = [[OrdersViewController alloc] initWithNibName:#"OrdersViewController" bundle:nil];
ordersView.title = #"ordersView";
UINavigationController *myorderController = [[[UINavigationController alloc] initWithRootViewController:ordersView] autorelease];
myorderController.navigationBar.barStyle = UIBarStyleBlack;
[listOfViewControllers addObject:myorderController];
[ordersView release];
orderList = [[OrderListViewController alloc] initWithNibName:#"OrderListViewController" bundle:nil];
orderList.title = #"orderList";
UINavigationController *myorderListController = [[[UINavigationController alloc] initWithRootViewController:orderList] autorelease];
myorderListController.navigationBar.barStyle = UIBarStyleBlack;
[listOfViewControllers addObject:myorderListController];
[orderList release];
productView = [[ProductViewController alloc] initWithNibName:#"ProductViewController" bundle:nil];
productView.title = #"productView";
UINavigationController *myproductController = [[[UINavigationController alloc] initWithRootViewController:productView] autorelease];
[listOfViewControllers addObject:myproductController];
[productView release];
[self.tabBarController setViewControllers:listOfViewControllers animated:YES];
NSArray *segmentTextContent = [NSArray arrayWithObjects:NSLocalizedString(#"Dashboard", #""),NSLocalizedString(#"Order", #""),
NSLocalizedString(#"Product", #""),NSLocalizedString(#"More", #""),
nil];
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
segmentedControl.selectedSegmentIndex = 0;
segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.frame = CGRectMake(0, 0, 400, 40);
[segmentedControl addTarget:self action:#selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
//defaultTintColor = [segmentedControl.tintColor retain]; // keep track of this for later
segmentedControl.tintColor = [UIColor colorWithHue:8.0 saturation:8.0 brightness:8.0 alpha:1.0];
segmentedControl.alpha = 0.8;
self.navigationItem.titleView = segmentedControl;
[segmentedControl release];
}
If it is not clear to you then please knock...

Resources