Custom UITabBar that expand on selection - iphone

I am trying to achieve the below attach image on the UITabbar.
http://i.imgur.com/7Tukx.png
It's pretty straight forward, on selection the tab expand with a label to display text and on selection on another tab, the selected tab will collapse.
I am not really sure how to do this with the UItabbar.
I will appreciate if anyone could point me in the right direction.

for the custom tab you use this method on appdelegate class
this method create two tab bar item.
and you set your image..
-(void)SetTabs
{
tabBarController = [[UITabBarController alloc]init];
NSMutableArray *localControllerArray = [[NSMutableArray alloc]initWithCapacity:2];
UIImage *image = [UIImage imageNamed:#"home.png"];
GreetingCardsViewController *GreetingCardsView = [[[GreetingCardsViewController alloc] initWithNibName:#"GreetingCardsViewController" bundle:nil] autorelease];
UITabBarItem *item = [[UITabBarItem alloc]initWithTitle:#"Home" image:image tag:0];
UINavigationController *GreetingCardsViewNavigationController = [[UINavigationController alloc]initWithRootViewController:GreetingCardsView];
GreetingCardsView.tabBarItem = item;
[localControllerArray addObject:GreetingCardsViewNavigationController];
UIImage *image1 = [UIImage imageNamed:#"heart1.png"];
Cards *CardView = [[[Cards alloc] initWithNibName:#"Cards" bundle:nil] autorelease];
UITabBarItem *item1 = [[UITabBarItem alloc]initWithTitle:#"Cards" image:image1 tag:1];
UINavigationController *CardNavigationController = [[UINavigationController alloc]initWithRootViewController:CardView];
CardNavigationController.tabBarItem = item1;
[localControllerArray addObject:CardNavigationController];
[tabBarController setViewControllers:localControllerArray];
[_window addSubview:tabBarController.view];
[localControllerArray release];
}

I'm not entirely sure what you're after, however I think this may be relevant to you. You could use the basic concept and tweak it to what you need.

Related

iOS: UINavigationBar title doesn't appear

I am not sure what's going wrong with my UINavigationBar title things. I am not able to get it working after trying all possible things. The navigation bar appears but title is missing!! Here is my simple code,
self.marketsListViewController = [[MarketsListViewController alloc] initWithNibName:#"MarketsListViewController" bundle:nil];
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:self.marketsListViewController];
nvc.navigationBar.barStyle = UIBarStyleBlack;
[self.marketsListView addSubview:nvc.view];
[self addChildViewController:nvc];
[nvc didMoveToParentViewController:self];
In MarketsListViewController's didViewLoad, I have tried all of following and none of them worked!!! Could someone please help me to understand what's going on? Thanks.
self.title = #"MyTitle";
self.navigationItem.title = #"MyTitle";
self.navigationController.navigationItem.title = #"MyTitle";
There seem to be some changes in UINavigationController from iOS6.
https://stackoverflow.com/a/13205842/1171003
When I wrote code like this, the title was not shown at all.
UITabBarController *tb = [[UITabBarController alloc] init];
tb.viewControllers = [NSArray arrayWithObjects:
[[ViewController1 alloc] init],
[[ViewController2 alloc] init],
nil];
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:tb];
However, after I added this line, it appeared.
tb.title = #"Title";

How to Customise my Tabbar controller icons (background images)?

I have an iphone application in which i wanted to show my own images as the tabbar icons.but now only the default greyone is coming.i need to change it to the my own images?.I went through lot of links,but nothing seems to be very clear.that can anybody know how to achieve this?
Please download source code from here and change images according to your requirement.
You can set image on tabBarItem like this :-
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate = self;
ViewController *viewObject= [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UINavigationController *navView = [[UINavigationController alloc] initWithRootViewController: viewObject];
UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Tutorial" image:[UIImage imageNamed:#"kb-emoji-U+E031.png"] tag:1];
navView.tabBarItem = tabBarItem;
tabBarController.viewControllers = [NSArray arrayWithObjects:navView,nil];
self.window.rootViewController = tabBarController;
Also see this link - click me

UITabBarItems aren't centering in custom sized UITabBar

My UITabBarItems aren't showing up vertically centered in my UITabBar. I am using a custom sized background image for my UITabBar.
UITabBarController *tabController = [[UITabBarController alloc] init];
UITabBar *tabBar = [controller tabBar];
UIImage *backgroundImage = [UIImage imageNamed:#"Images/bottomBar.png"];
[tabBar setBackgroundImage:backgroundImage];
SplashScreenController *introController = [[SplashScreenController alloc] init];
UIImage *introImage = [UIImage imageNamed:#"Images/navIntro.png"];
UITabBarItem *introItem = [[UITabBarItem alloc] initWithTitle:#"Intro" image:introImage tag:0];
[introController setTabBarItem:introItem];
NSMutableArray *controllers = [[NSMutableArray alloc] init];
[controllers addObject:introController];
NSArray *controllers = [self createControllers];
[tabController setViewControllers:controllers];
It looks like you are missing the retina version of your files, such as a 60x60 navIntro#2x.png. The navIntro#2x.png file needs to be in your project, but in code you would still reference the file as navIntro.png.

Setting custom UITabBarItem programmatically?

In iOS, the TabBar property in the TabBarController is read only. How can I associate a custom item with a particular view controller? How do I access the UITabBarItems inside the tabBar?
Like this
CustomView *custom = [[CustomView alloc] init];
UITabBarItem *customTab = [[UITabBarItem alloc] initWithTitle:#"Custom" image:[UIImage imageNamed:#"custom.png"] tag:0];
SecondView *second = [[SecondView alloc] init];
UITabBarItem *secondTab = [[UITabBarItem alloc] initWithTitle:#"Next" image:[UIImage imageNamed:#"next.png"] tag:1];
NSArray *views = [NSArray arrayWithObjects:custom,second,nil];
[tabBarController setViewControllers:views];
//how do I set the individual TabBarItems (customTab,secondTab) to be associated
//with the views in question? tabBarController.tabBar is read only
Inside each view controller, you can set a tabBarItem property. If the view controller is owned by a UITabBarViewController the associated item on the tab bar will be updated accordingly.
Something like this
-(void)viewDidLoad {
[super viewDidLoad];
UITabBarItem *tbi = [[UITabBarItem alloc] initWithTitle:yourTitle image:yourIcon tag:yourTag];
[self setTabBarItem:tbi]
[tbi release];
}
You are not restricted to perform this operation in the viewDidLoad method, obviously.

UITabBar with UINavigationController in code

I've currently got a UITabBar with 5 screens calling UIViews. That part works fine but I want to put in a UINavigationController in a couple of them. I have found a few tutorials that work fine but all of them implement it in IB and I want to avoid that if possible.
I'm lost as to where to implement the UINavigationController, should I do it in the App Delegate with the UITabBar and call the navigation controller from the UIView or should I create it in the UIView class?
I've tried about 8 different ways and always ends up with either the Navbar not working, no nav bar at all or the app crashing.
Currently I create the tab bar like this:
tabBarController = [[UITabBarController alloc] init];
ScreenA *screenA = [[ScreenA alloc] initWithNibName:#"ScreenA" bundle:nil];
//more here
tabBarController.viewControllers = [NSArray arrayWithObjects:screenA, ...., nil];
[window addSubview:tabBarController.view];
And in the initWithNibName I have this:
self.title = #"Screen A";
self.tabBarItem.image = [UIImage imageNamed:#"someImage.png"];
Ok, do it like this...
tabBarController = [[UITabBarController alloc] init];
searchTableViewController = [[SearchTableViewController alloc] init];
UINavigationController *searchTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchTableViewController] autorelease];
[searchTableViewController release];
searchMapViewController = [[SearchMapViewController alloc] init];
UINavigationController *mapTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchMapViewController] autorelease];
[searchMapViewController release];
tabBarController.viewControllers = [NSArray arrayWithObjects:searchTableNavController, mapTableNavController, nil];