I want to make it translucent black, why doesn't this work?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UINavigationController *viewController1 = [[UINavigationController alloc] init];
viewController1.navigationBar.barStyle = UIBarStyleBlackTranslucent;
RSSViewController *rssViewController = [[RSSViewController alloc] init];
[viewController1 addChildViewController:rssViewController];
UIViewController *viewController2 = [[CalendarViewController alloc] initWithNibName:#"CalendarViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
[self customizeInterface];
return YES;
}
When I put viewController1.navigationBar.barStyle = UIBarStyleBlackTranslucent; navigation items simply disappear...
Use this
viewController1.navigationBar.tintColor = [UIColor blackColor];
viewController1.navigationBar.translucent = YES;
Related
This is my AppDelegate, i set a title "Pizza", but when i build and play the application, the text don't will appear.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UITabBarController *tabBarController = [[UITabBarController alloc]init];
ListaPizzeViewController *listPizzeVC = [[ListaPizzeViewController alloc]init];
UINavigationController *navigationControllerPizza = [[UINavigationController alloc]initWithRootViewController:listPizzeVC];
[navigationControllerPizza setTitle:#"Pizza"];
navigationControllerPizza.tabBarItem.image = [UIImage imageNamed:#"Default.png"];
ListIngredientsViewController *listIngredientVC = [[ListIngredientsViewController alloc]init];
UINavigationController *navigationControllerIngradient = [[UINavigationController alloc]initWithRootViewController:listIngredientVC];
[navigationControllerIngradient setTitle:#"Ingredient"];
navigationControllerIngradient.tabBarItem.image = [UIImage imageNamed:#"Default.png"];
[tabBarController setViewControllers:#[navigationControllerPizza, navigationControllerIngradient]];
[self.window setRootViewController:tabBarController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Why?
According to Your Question you can set title of ListaPizzeViewController using object of ListaPizzeViewController like Bellow:-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UITabBarController *tabBarController = [[UITabBarController alloc]init];
ListaPizzeViewController *listPizzeVC = [[ListaPizzeViewController alloc]init];
UINavigationController *navigationControllerPizza = [[UINavigationController alloc]initWithRootViewController:listPizzeVC];
[listPizzeVC setTitle:#"Pizza"]; // Here it is you can set Title of Object of Viewcontroller so set like thin not [navigationControllerPizza setTitle:#"Pizza"];
navigationControllerPizza.tabBarItem.image = [UIImage imageNamed:#"Default.png"];
ListIngredientsViewController *listIngredientVC = [[ListIngredientsViewController alloc]init];
UINavigationController *navigationControllerIngradient = [[UINavigationController alloc]initWithRootViewController:listIngredientVC];
[navigationControllerIngradient setTitle:#"Ingredient"];
navigationControllerIngradient.tabBarItem.image = [UIImage imageNamed:#"Default.png"];
[tabBarController setViewControllers:#[navigationControllerPizza, navigationControllerIngradient]];
[self.window setRootViewController:tabBarController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
go into your ListaPizzeViewController, inside the viewDidLoad write
self.title = #"Pizze";
self.navigationItem.title=#"pizza";
simply call this.
Try to set title in viewWillAppear method.
of "listPizzeVC" as
self.title=#"Pizza";
IT is title is ViewController property so use view controller object and title set I write the code under.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UITabBarController *tabBarController = [[UITabBarController alloc]init];
ListaPizzeViewController *listPizzeVC = [[ListaPizzeViewController alloc]init];
UINavigationController *navigationControllerPizza = [[UINavigationController alloc]initWithRootViewController:listPizzeVC];
//[navigationControllerPizza setTitle:#"Pizza"];
listPizzeVC.title=#"Pizza";
navigationControllerPizza.tabBarItem.image = [UIImage imageNamed:#"Default.png"];
ListIngredientsViewController *listIngredientVC = [[ListIngredientsViewController alloc]init];
UINavigationController *navigationControllerIngradient = [[UINavigationController alloc]initWithRootViewController:listIngredientVC];
//[navigationControllerIngradient setTitle:#"Ingredient"];
listIngredientVC.title=#"Ingredient";
navigationControllerIngradient.tabBarItem.image = [UIImage imageNamed:#"Default.png"];
[tabBarController setViewControllers:#[navigationControllerPizza, navigationControllerIngradient]];
[self.window setRootViewController:tabBarController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
I hope it is useful too.
Your code should not be in the appDelegate but in a viewcontroller class that inherits from UIViewController and attach this class to your xib or storyboard screen. One viewcontroller per screen. Add your code to the viewDidLoad or create your own methods. When this doesn't work you might wanna try and post your question again. ;).
I recently started iOS development, it helped me to take little steps and create small project that aimed for learning one thing at a time this way you will learn really fast and efficient without too much frustration. Good luck!
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 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
Good day. I try to add new tab with navigation controller to my app. I create a new tabbed app (xcode 4.2) and in appdelegate write this
- (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 = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil] autorelease];
NavController *navController = [[[NavController alloc] initWithNibName:#"NavController" bundle:nil] autorelease]; //my controller
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, navController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
NavController.h file
#interface NavController : UINavigationController
#end
Here the structure of project
And when I run project it show me empty tab
But in xib file I add lable and buttons
May be I forgot something?
Initialise your navigation controller with some UIViewController that is :
RootViewController *rootViewController = [[[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil] autorelease];
NavController *navController = [[[NavController alloc] initWithRootViewController: rootViewController] autorelease];
This might help.
i am sharing you my APP Code about this feature,Hope this can solve your Problem easily
Add this code in AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
UINavigationController *localNavigationController;
tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:3];
viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[localControllersArray addObject:localNavigationController];
AlaramClock *aAlaramClock = [[[AlaramClock alloc] initWithNibName:#"AlaramClock" bundle:nil] autorelease];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:aAlaramClock];
[localControllersArray addObject:localNavigationController];
CurrentTime *aCurrentTime = [[[CurrentTime alloc] initWithNibName:#"CurrentTime" bundle:nil] autorelease];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:aCurrentTime];
[localControllersArray addObject:localNavigationController];
Settings *aSettings = [[[Settings alloc] initWithNibName:#"Settings" bundle:nil] autorelease];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:aSettings];
[localControllersArray addObject:localNavigationController];
tabBarController.viewControllers = localControllersArray;
[localControllersArray release];
// Override point for customization after app launch
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
return YES;
}
Then U will get this look
after this in Every ViewController.m
ADD this
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
// Custom initialization
self.title=#"Calculate Time";
self.tabBarItem.title = #"Calculate Time";
self.tabBarItem.image=[UIImage imageNamed:#"time_calculate.png"];
}
return self;
}
I'm trying to put a TTThumbsViewController inside a UITabBarController, but when I do, the TTThumbsViewController's NavigationBar doesn't show. There is just blank space where the NavigationBar should be. I've loaded just the TTThumbsViewController by itself, and the NavigationBar loads just fine. I'm sure I've just missed a setting, but I can't figure out what it is.
Here is what I'm doing to create the UITabBarController and the TTThumbsViewController:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.tabBarController = [[UITabBarController alloc] init];
ThumbsViewController *thumbsViewController = [[ThumbsViewController alloc] init];
UITabBarItem *thumbsTabBarItem = [[UITabBarItem alloc] initWithTitle:#"Thumbs" image:[UIImage imageNamed:#"icon.png"] tag:Thumbs];
thumbsViewController.tabBarItem = thumbsTabBarItem;
self.tabBarController.viewControllers = [NSArray arrayWithObjects:thumbsViewController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
If you're loading the TTThumbsViewController from a UITabController, you need to create the UINavigationController yourself.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.tabBarController = [[UITabBarController alloc] init];
ThumbsViewController *thumbsViewController = [[ThumbsViewController alloc] init];
UITabBarItem *thumbsTabBarItem = [[UITabBarItem alloc] initWithTitle:#"Thumbs" image:[UIImage imageNamed:#"icon.png"] tag:Thumbs];
thumbsViewController.tabBarItem = thumbsTabBarItem;
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:ThumbsViewController] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}