UI_UItabBarController
2015-10-08 10:55
316 查看
AppDelegate.m #import "AppDelegate.h" #import "FirstViewController.h" #import "SecondViewController.h" #import "ThirdViewController.h" #import "FourthViewController.h" #import "FifthViewController.h" #import "SixthViewController.h" @interface AppDelegate ()<UITabBarControllerDelegate> @end @implementation AppDelegate - (void)dealloc { [_window release]; [super dealloc]; } // 实时监控选择的tabbar的索引. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { NSLog(@"%ld", tabBarController.selectedIndex); viewController.tabBarItem.badgeValue = nil; viewController.tabBarItem.badgeValue = @""; } - (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]; [_window release]; 1.创建第一个tabbar. FirstViewController *first = [[FirstViewController alloc] init]; UINavigationController *firsthNC = [[UINavigationController alloc] initWithRootViewController:first]; // 设定tabbarItem的内容. firsthNC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1000] autorelease]; 2.创建第二个tabbar. SecondViewController *second = [[SecondViewController alloc] init]; UINavigationController *secondNC = [[UINavigationController alloc] initWithRootViewController:second]; secondNC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"朋友圈" image:[UIImage imageNamed:@"1"] selectedImage:[UIImage imageNamed:@"3"]]autorelease]; secondNC.tabBarItem.badgeValue = @"+1"; 3.创建第三个tabbar. ThirdViewController *third = [[ThirdViewController alloc] init]; UINavigationController *thirdNC = [[UINavigationController alloc] initWithRootViewController:third]; thirdNC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"分享" image:[UIImage imageNamed:@"2"] tag:1001] autorelease]; thirdNC.tabBarItem.badgeValue = @"+99"; 4.创建第四个tabbar. FourthViewController *fourth = [[FourthViewController alloc] init]; UINavigationController *fourthNC = [[UINavigationController alloc] initWithRootViewController:fourth]; fourthNC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1002]; 5.创建第五个tabbar. FifthViewController *fifth = [[FifthViewController alloc] init]; UINavigationController *fifthNC = [[UINavigationController alloc] initWithRootViewController:fifth]; fifthNC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1003]; 6.创建第六个tabbar. SixthViewController *sixth = [[SixthViewController alloc] init]; UINavigationController *sixthNC = [[UINavigationController alloc] initWithRootViewController:sixth]; sixthNC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:1004]; 7.需要将这些tabBarController加入到数组中 // 设置数组. UITabBarController *tab = [[UITabBarController alloc] init]; tab.viewControllers = @[firsthNC, secondNC, thirdNC, fourthNC, fifthNC,sixthNC]; self.window.rootViewController = tab; // 设置外观tabbar tab.tabBar.translucent = NO; // 背景颜色. tab.tabBar.barTintColor = [UIColor magentaColor]; // 选中后的颜色. tab.tabBar.tintColor = [UIColor blackColor]; // 默认起始页. tab.selectedIndex = 2; tab.delegate = self; [first release]; [firsthNC release]; [tab release]; [second release]; [secondNC release]; [third release]; [thirdNC release]; [fourth release]; [fourthNC release]; [fifth release]; [fifthNC release]; [sixth release]; [sixthNC release]; return YES; }
相关文章推荐
- UIAlterViewDelegate简单总结
- apue.h头文件(UNIX环境高级编程)
- UI:动画
- 给UIview加上xib
- iOS开发之UITabBarController
- iOS-UITableviewCell的重用机制
- iOS开发工具Xcode:Interface Builder
- Mniui 学习笔记 2
- UI Testing in Xcode 7
- marguee实现最新公告动态轮播效果
- LeetCode 51 N-Queens
- UItableViewCell 编辑移动
- iOS开发之窥探UICollectionViewController(四) --一款功能强大的自定义瀑布流
- jsp ueditor 图片在线管理图片路径
- Exported service does not require permission警告
- iOS的UIColor类与其相关类之间的区别及判断相等的方法
- Block高级用法:Block传值UI_12(3)
- UITabBarController及三种控制器的…
- 导航控制器 UI_08(上)
- UIPassValue页面传值 UI_08(下)