iPhone XCode - How to create a simple UITabBar

A simple demonstration by code on how to implement a UITabBar on iPhone.

1.) Create a new Windows based project, and named it whatever you want.

2.) You should look up for 2 files, .h and .m (I named mine MyTab).

#import <UIKit/UIKit.h>

@interface MyTabAppDelegate : NSObject  {
    UIWindow *window;
    UITabBarController *tabBarController;

@property (nonatomic, retain) IBOutlet UIWindow *window;


#import "MyTabAppDelegate.h"

@implementation MyTabAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
 //initialize the UITabBarController
 tabBarController = [[UITabBarController alloc] init];
 //Create the first UITabBarItem
 UIViewController *viewController1 = [[UIViewController alloc] init];
 [viewController1 setTitle:@"MyTab1"];
 //note that you can set the tab bar item's icon by uncommenting the line below
 //viewController1.tabBarItem.image =  [UIImage imageNamed:@"any image in your resource"];
 viewController1.view.backgroundColor = [UIColor orangeColor];
 //Create the second UITabBarItem
 UIViewController *viewController2 = [[UIViewController alloc] init];
 [viewController2 setTitle:@"MyTab2"];
 viewController2.view.backgroundColor = [UIColor redColor];
 //add the UIViewControllers to the UITabController
 tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
 [viewController1 release];
 [viewController2 release];
 //add to the main window
 [window addSubview:tabBarController.view];
    // Override point for customization after application launch
    [window makeKeyAndVisible];

- (void)dealloc {
    [window release];
    [super dealloc];

iPhone XCode - How to create a simple UITabBar iPhone XCode - How to create a simple UITabBar Reviewed by Edward Legaspi on Sunday, December 26, 2010 Rating: 5

No comments:

Powered by Blogger.