app.m
#import "AppDelegate.h" #import "TmailViewController.h" #import "TaoBaoViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; //淘宝页面 TaoBaoViewController *taobao =[[TaoBaoViewController alloc] init]; UINavigationController *taoNav=[[UINavigationController alloc] initWithRootViewController:taobao]; //设置标题 taoNav.tabBarItem.title=@"淘宝"; //设置未选中的图片 taoNav.tabBarItem.image=[UIImage imageNamed:@"taobao"]; //设置选中时的图片 taoNav.tabBarItem.selectedImage=[UIImage imageNamed:@"taobao"]; //天猫页面 TmailViewController *tmall =[[TmailViewController alloc] init]; UINavigationController *tmallNav=[[UINavigationController alloc]initWithRootViewController:tmall]; //设置标题 tmallNav.tabBarItem.title=@"天猫"; //设置未选中的图片 tmallNav.tabBarItem.image=[UIImage imageNamed:@"tianmao"]; //设置选中时的图片 tmallNav.tabBarItem.selectedImage=[UIImage imageNamed:@"tianmao"]; //统一设置导航栏的格式 [[UINavigationBar appearance] setBarTintColor:[UIColor greenColor]]; [[UINavigationBar appearance] setTranslucent:NO]; UITabBarController *tabbarC =[[UITabBarController alloc]init]; // 将页面放在tabbarcontroller 中 tabbarC.viewControllers= [NSArray arrayWithObjects:taoNav,tmallNav,nil]; //把tabbarcontroller 作为window的根视图 self.window.rootViewController =tabbarC; return YES; }
taobao.m
#import "TaoBaoViewController.h" @interface TaoBaoViewController () @end @implementation TaoBaoViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor=[UIColor blueColor]; self.navigationItem.title=@"淘宝"; } @end
tmail.m
#import "TmailViewController.h" @interface TmailViewController () @end @implementation TmailViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor=[UIColor yellowColor]; self.navigationItem.title=@"天猫"; } @end