UIday1302:标签视图控制器 UITabBarController
2015-09-10 22:17
459 查看
标签视图控制器 UITabBarController
ViewController //控制视图 控制n个viewController
//控制控制器
NavigationController //除了控制n个viewController还可以控制n个TabBarController
TabBarController //除了控制n个viewController还可以控制n个navigationController
NC控制多个TC TC再控制VC
TC控制多个NC NC再控制VC
AppDelegate.m
ViewController //控制视图 控制n个viewController
//控制控制器
NavigationController //除了控制n个viewController还可以控制n个TabBarController
TabBarController //除了控制n个viewController还可以控制n个navigationController
NC控制多个TC TC再控制VC
TC控制多个NC NC再控制VC
AppDelegate.m
#import "AppDelegate.h" #import "TabBarViewController.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]; // 创建好一个标签控制器 TabBarViewController * tabC = [[TabBarViewController alloc]init]; // 一般使用tabBarController作为根视图控制器 self.window.rootViewController = tabC; //换肤 appearance是个单例 [[UITabBar appearance]setBarTintColor:[UIColor blueColor]]; [[UITabBar appearance]setBackgroundImage:[UIImage imageNamed:@"202.png"]]; //navigationBar换肤 [[UINavigationBar appearance]setBarTintColor:[UIColor yellowColor]]; [[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"202.png"] forBarMetrics:(UIBarMetricsDefault )]; return YES; } @endTabBarViewController.m
#import "TabBarViewController.h" #import "YellowViewController.h" #import "BlueViewController.h" #import "GreenViewController.h" #import "RedViewController.h" #import "GrayViewController.h" #import "OrangaViewController.h" @interface TabBarViewController ()<UITabBarControllerDelegate> @end @implementation TabBarViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //创建视图控制器 (tabBarItem设置在这里才会一起显示出来,当前默认显示出来的是第一个视图控制器,alloc init 此时并不会加载后面的视图控制器) YellowViewController * yellowVC = [[YellowViewController alloc]init]; yellowVC.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemContacts tag:110]; //角标 yellowVC.tabBarItem.badgeValue = @"99+"; //每个视图控制器单独设置自己的tabBarItem BlueViewController * blueVC = [[BlueViewController alloc]init]; blueVC.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:111]; blueVC.tabBarItem.badgeValue = @"哈罗"; GreenViewController * greenVC = [[GreenViewController alloc]init]; greenVC.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:112]; greenVC.tabBarItem.badgeValue = @"hello"; RedViewController * redVC = [[RedViewController alloc]init]; redVC.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:113]; redVC.tabBarItem.badgeValue = @"5"; GrayViewController * grayVC = [[GrayViewController alloc]init]; grayVC.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemRecents tag:115]; OrangaViewController * orangaVC = [[OrangaViewController alloc]init]; orangaVC.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemSearch tag:116]; //所有显示的controller都显示在这个数组里 //这里最多可以显示5个,5个以上的会在第五个显示一个more图标,点即more图标可以看到没有显示的其他几个controller //平常设计 建议最多不要超过4个 self.viewControllers = @[yellowVC,blueVC,greenVC,redVC]; //选中要显示的视图控制器,以数组下标为依据 self.selectedIndex = 0; //自己设置自己的代理 self.delegate = self; //换颜色 self.tabBar.barTintColor = [UIColor greenColor]; //换图片 // self.tabBar.backgroundImage = [UIImage imageNamed:@"202.png"]; // NSLog(@"Image = %@",[UIImage imageNamed:@"202.png"]); //是每个UIViewController的 // self.navigationItem } #pragma mark ----tabBarController Delegate //选中响应的controller - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ NSLog(@"%@",viewController); //取消小圆点 viewController.tabBarItem.badgeValue = nil; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- ucGUI 文本显示(一)
- UIday1202:单例
- UIImageView的图片拉伸
- UIImageView的图片拉伸
- UIday1201:模态
- 【iOS7一些总结】9、与列表显示(在):列表显示UITableView
- [LeetCode] Unique Paths
- UITextField
- Rust - Unique pointers | 独一无二的指针(所有权指针)
- UITableView使用<2>UITableViewCell的介绍
- UIButton
- COCI CONTEST #3 29.11.2014 T3 SILUETA
- UIlabel
- NGUI使用图集的精灵换图片
- IOS-UI-视图控件UIview
- iOS:集合视图UICollectionView、集合视图控制器UICollectionViewController、集合视图单元格UICollectionViewCell(创建表格的另一种控件)
- CodeForces 11A - Increasing Sequence
- Illegal instant due to time zone offset transition (Asia/Shanghai)
- HDU4620 Fruit Ninja Extreme(搜索+剪枝)
- HotSpot Builder Utility安装指南