In the (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method, I initialized an instance of UINavigationController with GeneralOptionsTableViewController and an instance of GeneralOptionsMapViewController. The navigationBar color was set to green. However, when I switch between the UINavigationController with GeneralOptionsTableViewController and GeneralOptionsMapViewController, the navigationBar becomes transparent. I tried resetting the navigationbar color in the viewWillAppear method but it does not seem to work.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
GeneralObjectTableViewController *generalObjectTableViewController = [[GeneralObjectTableViewController alloc] init];
GeneralObjectMapViewController *generalObjectMapViewController = [[GeneralObjectMapViewController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:generalObjectTableViewController];
navigationController.navigationBar.barTintColor = [UIColor greenColor];
UITabBarController *tabBarController = [[UITabBarController alloc]init];
[tabBarController setViewControllers:[NSArray arrayWithObjects:navigationController, generalObjectMapViewController, nil]];
[self.window setRootViewController:tabBarController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Related
i want to see which view is offscreen-rendered in my app.So i use the iOS simulator's 'color offscreen-rendered' function,it can color those offscreen-rendered view by yellow color.But after the app launched,the whole screen is colored by yellow and i don't believe it.
Then i try my test code like:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[UITabBarController alloc] init];
// self.window.rootViewController = [[UINavigationController alloc] init];
// self.window.rootViewController = [[UIViewController alloc] init];
[self.window makeKeyWindow];
}
As you can see above,i simply set the window's rootViewController three times different by orginal controllers: 'UITabBarController','UINavigationController' and 'UIViewController'.
Guess what?
Only the 'UIViewController' is not whole screen colored!!!
So anyOne knows why the orginal rootViewController and UINavigationController will occur the whole screen offscreen-render??????
It's because default translucent value of UITabBar and UINavigationBar are YES.
You should check Apple documents for UINavigationBar.translucent and UITabBar.translucent for more information.
A small demo by creating a UINavigationController with a red background root view controller, we can compare the difference when translucent is YES and NO.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
UIViewController* viewController = [[UIViewController alloc] init];
viewController.view.backgroundColor = [UIColor redColor];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
// nav.navigationBar.translucent = NO;
self.window.rootViewController = nav;
[self.window makeKeyWindow];
return YES;
}
By default, translucent is YES. So you can see background of UINavigationBar has a little red.
Color offscreen-rendered
But when we set translucent to NO. No more red in background of UINavigationBar.
Color offscreen-rendered
We have transparent here so that's why screen is colored. You can try similar thing with translucent of UITabBar.
To avoid offscreen-rendered with UINavigationController and UITabBarController, you should set this property to NO.
I have tried to code a tab view controller in my AppDelegate and I can either change my background color and have no tab bar at the bottom of the screen, or have no background color and an empty tab bar at the bottom.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController.tabBar setHidden:NO];
self.firstViewController = [[FirstViewController alloc] init];
[self.firstViewController.view setBackgroundColor:[UIColor redColor]];
self.secondViewController = [[SecondViewController alloc] init];
self.topTracksController = [[TopTracksViewController alloc] init];
self.settingsViewController = [[SettingsViewController alloc] init];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
[self.window setRootViewController:self.tabBarController];
[self.window makeKeyAndVisible];
return YES;
}
That is my code inside my AppDelegate currently, and I have items with images in my storyboard already.
In App Delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
WalkThrough *viewControllers=[[WalkThrough alloc]init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewControllers];
[self.window setRootViewController:self.navigationController];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
navigationController.navigationBar.hidden = YES;
self.window.backgroundColor = [UIColor clearColor];
[self.window makeKeyAndVisible];
return YES;
}
Try to disable interactivePopGestureRecognizer after [window makeKeyAndVisible].
The key to the problem is that interactivePopGestureRecognizer property is nil until both two conditions are met:
the navigationController is associated to the window
the window become key and visible
I copied the example from View Controller Catalog for iOS made some changes to the colour and expected to see them reflected on the simulator. Nothing happens ???
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIViewController *myViewController = [[MyViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];
[navigationController setNavigationBarHidden:NO animated:YES];
navigationController.title = #"Hello";
navigationController.navigationBar.barStyle = UIBarStyleBlack ;
navigationController.navigationBar.translucent = NO;
navigationController.navigationBar.tintColor = [UIColor blackColor];
navigationController.navigationBar.barTintColor = [UIColor greenColor];
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.rootViewController = navigationController;
[window makeKeyAndVisible];
return YES; }
What do I do wrong?
Several things: First: be sure than in the General information of your target app, in Main Interface field is blank. (If you donĀ“t find it, delete all *.storyboard files that you have).
Second: In your AppDelegate.h should be this property:
#property (strong, nonatomic) UIWindow *window;
And last: Change this in your code:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
In order to know changes is better step by step. (.title is in ViewController).
I made a UINavigationController, and I have it working just fine but I need to work with it now. I need files that are in sync with the controller. I build everything programatically.
How do I get these files set up?
AppDelegate.h:
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) UINavigationController *navigationController;
#property (strong, nonatomic) UIViewController *rvc;
AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.navigationController = [[UINavigationController alloc] init];
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0/255 green:126/255 blue:233/255 alpha:1]];
[self.window addSubview:[self.navigationController view]];
[self.navigationController pushViewController:self.rvc animated:YES];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Create a UIViewController subclass and make rvc property have type of that class. After that you can write your logic in the created subclass.
Proper didFinishLaunchingWithOptions implementation:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.navigationController = [[UINavigationController alloc] init];
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0/255 green:126/255 blue:233/255 alpha:1]];
self.window.rootViewController = self.navigationController;
self.rvc = [[<your_class_name> alloc] init];
[self.navigationController pushViewController:self.rvc animated:YES];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
it's simple you can apply this code :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *vc = [[UIViewController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0/255 green:126/255 blue:233/255 alpha:1]];
self.window.rootViewController = navigationController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}