Wednesday, January 22, 2014

iOS - Tab bar

Web Hosting


Use of tab bar

It's generally used to switch between various subtasks, views or models within the same view.
Example for tab bar is shown below
iOS Tutorial

Important properties

  • backgroundImage
  • items
  • selectedItem

Sample code and steps

1. Create a new project and select Tabbed Application instead of the View Based application and clicknext, Give the project name and select create.
2. Here two view controllers are created by default and a tab bar is added to our application.
3. The AppDelegate.m didFinishLaunchingWithOptions method is as follows
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] 
    bounds]];
    // Override point for customization after application launch.
    UIViewController *viewController1 = [[FirstViewController alloc] 
    initWithNibName:@"FirstViewController" bundle:nil];
    UIViewController *viewController2 = [[SecondViewController alloc] 
    initWithNibName:@"SecondViewController" bundle:nil];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = @[viewController1, 
    viewController2];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}
4. Here two view controllers are allocated and made as view controllers of our tab bar controller.
5. Now when we run the application we'll get the following output
iOS Tutorial


Web Hosting

No comments:

Post a Comment