I was wondering if there is a tutorial or any hints for this tab bar customization, when you select a tab bar and hold you can change the icons to user liking sort of like this (check the bottom).
[TAB] http://tapbots.com/software/tweetbot/
Use UIGestures
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UITabBarController *tabController = [[UITabBarController alloc] init];
UIViewController *viewController1 = [[UIViewController alloc] init];
// UIlongtapGusture alloc and add it to viewController1
UIViewController *viewController2 = [[UIViewController alloc] init];
// UIlongtapGusture alloc and add it to viewController2
UIViewController *viewController3 = [[UIViewController alloc] init];
// UIlongtapGusture alloc and add it to viewController3
UIViewController *viewController4 = [[UIViewController alloc] init];
// UIlongtapGusture alloc and add it to viewController4
tabController.viewControllers = [NSArray arrayWithObjects:viewController1,
viewController2,
viewController3,
viewController4, nil];
self.window.rootViewController = tabController;
[self.window makeKeyAndVisible];
return YES;
}
see the customization of the tab-bar here
Related
In my tab based application delegate i added the navigation controller as like the following,
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
UIViewController *viewController3 = [[view1 alloc] initWithNibName:#"view1" bundle:nil];
UIViewController *viewController4 = [[view2 alloc] initWithNibName:#"view2" bundle:nil];
UIViewController *viewController5 = [[view3 alloc] initWithNibName:#"view3" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[viewController1, viewController2,viewController3,viewController4,viewController5];
navigationController=[[UINavigationController alloc]initWithRootViewController:self.tabBarController];
[self.window addSubview:[navigationController view]];
self.window.rootViewController = self.navigationController;
i would not be able to added the title in each view. While adding it doesn showing the title?Pls help me to resolve this issue
use bellow code...
Here i add UINavigationController to every tab and also assign title for tab and also for UINavigationBar like bellow...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *viewController1, *viewController2, *viewController3, *viewController4, *viewController5;
UINavigationController *navviewController1 , *navviewController2, *navviewController3, *navviewController4, *navviewController5;
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[[YourViewController1 alloc] initWithNibName:#"YourViewController1" bundle:nil] autorelease];
navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
navviewController1.title = #"Home";
// navviewController1.navigationBarHidden=YES;
viewController2 = [[[YourViewController2 alloc] initWithNibName:#"YourViewController2" bundle:nil] autorelease];
navviewController2=[[UINavigationController alloc]initWithRootViewController:viewController2];
// navviewController2.navigationBarHidden=YES;
navviewController2.title = #"HowItsWork";
viewController3 = [[[YourViewController3 alloc] initWithNibName:#"YourViewController3" bundle:nil] autorelease];
navviewController3=[[UINavigationController alloc]initWithRootViewController:viewController3];
// navviewController3.navigationBarHidden=YES;
navviewController3.title = #"Join Us";
viewController4 = [[[YourViewController4 alloc] initWithNibName:#"YourViewController4" bundle:nil] autorelease];
navviewController4=[[UINavigationController alloc]initWithRootViewController:viewController4];
// navviewController4.navigationBarHidden=YES;
navviewController4.title = #"Become";
viewController5 = [[[YourViewController5 alloc] initWithNibName:#"YourViewController5" bundle:nil] autorelease];
navviewController5=[[UINavigationController alloc]initWithRootViewController:viewController5];
// navviewController4.navigationBarHidden=YES;
navviewController5.title = #"Contact Us";
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navviewController1, navviewController2,navviewController3,navviewController4,navviewController5, nil];
self.window.rootViewController = self.tabBarController;
}
[self.window makeKeyAndVisible];
}
2)OR
Also you can simple assign title in your particular class like bellow...
-(void)viewWillAppear:(BOOL)animated{
self.title = #"yourTitle";
}
i hope this helpful to you...
Go to viewdidload method in every tabbar controller & use line:
navigationController.title=#"hello";
In every viewcontroller viewdidload
self.navigationcontroler.title=#"firstVC";
"title" is the property of UIViewController and UINavigationController is the subclass of UIViewController you can also access it object of UINavigationController, just like navviewController.title = #"myTitle"; and for more detail check Apple Docs. Hope it will help. Cheers
You have added TabBar Controller inside a Navigation Controller so you cannot add title and arises this issue.
Try to add each navigation controller with View controller inside tabbar controller.
I mean add ur ViewController as a root View controller of navigation controller then add to tab Bar controller.
viewController1 = [[[YourViewController1 alloc] initWithNibName:#"YourViewController1" bundle:nil] autorelease];
navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
Now then ad this navigation controller inside to tabbar controller. Do this for all other viewcontrollers
The title pretty much says it all. I'm trying to create an interface where after connecting with Facebook, the window loads up my HomeViewController (my initially selected UITabBarItem). Although, I do not want the UINavigationBar that comes through as I have set the HomeViewController as the LoginViewController's root view. I have different navigation bar items for each view, so defaulting to that one won't work. I have this code now.
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.mainViewController = [[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.mainViewController];
self.window.rootViewController = self.navigationController;
}
Create your custom tabbar Class add it in appDelegate
appDelegate.m
self.tabBarVC = [[[TabBarVC alloc] init] autorelease];
self.navController = [[[UINavigationController alloc]initWithRootViewController:self.tabBarVC]autorelease];
self.window.rootViewController = self.navController;
TabBarVC.h
#import <UIKit/UIKit.h>
#interface TabBarVC : UITabBarController
#end
TabBarVC.m
#import "TabBarVC.h"
#import "ViewController1.h"
#import "ViewController2.h"
#implementation TabBarVC
- (void)viewDidLoad
{
[super viewDidLoad];
UIViewController *vc1 = [[UIViewController alloc] initWithNibName:#"ViewController1" bundle:nil];
UIViewController *vc2 = [[UIViewController alloc] initWithNibName:#"ViewController2" bundle:nil];
[self setViewControllers:[NSArray arrayWithObjects:vc1,vc2, nil]];
}
#end
After a good nights sleep, I was able to figure it out. Hopefully, this can help others out there!
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.tabBarController = [[UITabBarController alloc] init];
// Initialize view controllers
HomeViewController *homeViewController = [[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:nil];
ConnectViewController *connectViewController = [[ConnectViewController alloc] initWithNibName:#"ConnectViewController" bundle:nil];
PartyControlViewController *partyControlViewController = [[PartyControlViewController alloc] initWithNibName:#"PartyControlViewController" bundle:nil];
MeViewController *meViewController = [[MeViewController alloc] initWithNibName:#"MeViewController" bundle:nil];
MoreViewController *moreViewController = [[MoreViewController alloc] initWithNibName:#"MoreViewController" bundle:nil];
[self.tabBarController setViewControllers:[NSArray arrayWithObjects:homeViewController, connectViewController, partyControlViewController, meViewController, moreViewController, nil]];
// Customize Tab Bar
UITabBarItem *homeTab = [[UITabBarItem alloc] initWithTitle:#"Home" image:nil tag:0];
UITabBarItem *connectTab = [[UITabBarItem alloc] initWithTitle:#"Connect" image:nil tag:1];
UITabBarItem *partyControlTab = [[UITabBarItem alloc] initWithTitle:#"Party Control" image:nil tag:2];
UITabBarItem *meTab = [[UITabBarItem alloc] initWithTitle:#"Me" image:[UIImage imageNamed:#"person.png"] tag:3];
UITabBarItem *moreTab = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMore tag:4];
[homeViewController setTabBarItem:homeTab];
[connectViewController setTabBarItem:connectTab];
[partyControlViewController setTabBarItem:partyControlTab];
[meViewController setTabBarItem:meTab];
[moreViewController setTabBarItem:moreTab];
self.window.rootViewController = self.tabBarController;
}
I have a problem in my appdelegate. I want to add a navigation bar, but it doesn't work.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.tabBarController = [[UITabBarController alloc] init];
UniversViewController *universViewController = [[UniversViewController alloc] initWithNibName:#"ProduitsListinTableViewController" bundle:nil];
universViewController.title = #"univers";
CategoriesViewController *categoriesViewController = [[CategoriesViewController alloc] initWithNibName:#"ProduitsListinTableViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:categoriesViewController];
navigationController.title = #"categories";
[navigationController setNavigationBarHidden:NO];
ProduitsListinTableViewController *produitListe = [[ProduitsListinTableViewController alloc] initWithNibName:#"ProduitsListinTableViewController" bundle:nil];
produitListe.title = #"troisième";
_tabBarController.viewControllers = [NSArray arrayWithObjects:universViewController, categoriesViewController, produitListe, nil];
[self.window setRootViewController:_tabBarController];
[self.window makeKeyAndVisible];
return YES;
}
Do I have to add something in UniversViewController, CategoriesViewController and ProduitsListinTableViewController or this is directly in the appdelegate?
Try this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1, *viewController2,*viewController3,*viewController4,*viewController5;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
viewController1 = [[[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:nil] autorelease];
navController=[[UINavigationController alloc] initWithRootViewController:viewController1];
viewController2 = [[[SearchViewController alloc] initWithNibName:#"SearchViewController" bundle:nil] autorelease];
navController2=[[UINavigationController alloc] initWithRootViewController:viewController2];
viewController3 = [[[LocationsViewController alloc] initWithNibName:#"LocationsViewController" bundle:nil] autorelease];
navController3=[[UINavigationController alloc] initWithRootViewController:viewController3];
viewController4 = [[[CallViewController alloc] initWithNibName:#"CallViewController" bundle:nil] autorelease];
navController4=[[UINavigationController alloc] initWithRootViewController:viewController4];
viewController5 = [[[MyBookingsViewController alloc] initWithNibName:#"MyBookingsViewController" bundle:nil] autorelease];
navController5=[[UINavigationController alloc] initWithRootViewController:viewController5];
}
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController,navController2,navController3,navController4,navController5,nil];
//self.window.rootViewController =self.navController;
self.window.rootViewController=self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
I always follow this approach when I have both a UINavigationController and a UITabbarController:
You need to start with a view based application. And then create a UITabbarController in your appDelegate file.
Appdelegate.h
UITabBarController *tabBarController;
// set properties
Appdelegate.m
// Synthesize
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
// Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController
Search * search = [[Search alloc] init];
UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:search];
Nearby* nearby = [[Nearby alloc] init];
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby];
Map* map = [[Map alloc] init];
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map];
AboutUs* aboutUs = [[AboutUs alloc] init];
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs];
Favorites* favorites = [[Favorites alloc] init];
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites];
NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil];
tabBarController.viewControllers = controllers;
[window addSubview:tabBarController.view];
You can accordingly manage in which tab you want to place navigation controller or only a view controller.
Then in each of the view controllers mentioned above you need to implement
- (id)init {}
in which you can set Tab name and image.
I always follow this approach and it never fails. The tabs are always visible. You can make changes according to your code.
I'm new in iPhone, I created application that is started with UITabbarController with 4 items using AppDelegate. through the app I opened some views and I want to relaunch the AppDelegate again by using a code like:
[appdelegate presentModalViewController:myNavController animated:YES];
is this possible?
this is in my AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
NSMutableArray *array = [[NSMutableArray alloc] init];
MaktabatyTableViewController *own = [[MaktabatyTableViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *ownNavController = [[UINavigationController alloc] initWithRootViewController:own];
[array addObject:ownNavController];
NewestTableViewController *newest = [[NewestTableViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *newestNavController = [[UINavigationController alloc] initWithRootViewController:newest] ;
[array addObject:newestNavController];
MostBuyTableViewController *mostbuy = [[MostBuyTableViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *mostbuyNavController = [[UINavigationController alloc] initWithRootViewController:mostbuy];
[array addObject:mostbuyNavController];
FreeBooksTableViewController *free = [[FreeBooksTableViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *freeNavController = [[UINavigationController alloc] initWithRootViewController:free];
[array addObject:freeNavController];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = array;
[self.window setBackgroundColor:[UIColor whiteColor]];
[self.window addSubview:self.tabBarController.view];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Thanks in advance.
I think you are looking for something like this..
A login screen which is a simple view with login fields, upon login, this screen is of no use. And the main app is based on tab bar.
And a Logout screen or A screen showing after user signed out.
I had this requirement in one of my app, so i made a sample template. May be it helps you checkout this.
I have implemented a tab bar controller in my App Delegate, but it's just empty squares in the tab bar. I wish to could change title and images of them and also I want to know how use not only custom image I add, but "default" images implemented in Xcode ("calculator" image, "search" image).
If you have tab bar in a xib, you can see it in tab bar item -> attributes inspector -> Identifier, then there is a list, if you don't want to use custom images. So there is my appDelegate.m code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after app launch
UIViewController *banksList = [[FailedBanksListViewController alloc] initWithNibName:#"FailedBanksListViewController" bundle:nil];
UINavigationController *listNavigationController = [[UINavigationController alloc] initWithRootViewController:banksList];
UIViewController *first = [[BIDViewController alloc] initWithNibName:#"BIDViewController" bundle:nil];
UIViewController *second = [[BIDDailyCount alloc] initWithNibName:#"BIDDailyCount" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:first,second,listNavigationController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
You have to create your UITabBarItems your self.
In you appdelegate you could do something like:
UIViewController *banksList = [[FailedBanksListViewController alloc] initWithNibName:#"FailedBanksListViewController" bundle:nil];
banksList.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:0];
return self;
It might be a good idea to move this to a custom initializer in the controllers for each tab.