UITabBarController继承于UIViewController
===================================================
在UITabBarController.m文件中
创建6个视图控制器
OneViewController *oneVC = [[OneViewController alloc] init];
TwoViewController *twoVC = [[TwoViewController alloc] init];
ThreeViewController *threeVC = [[ThreeViewController alloc] init];
FourViewController *fourVC = [[FourViewController alloc] init];
FiveViewController *fiveVC = [[FiveViewController alloc] init];
SixViewController *sixVC = [[SixViewController alloc] init];
创建导航控制器
UINavigationController *oneNav = [[UINavigationController alloc] initWithRootViewController:oneVC];
UINavigationController *twoNav = [[UINavigationController alloc] initWithRootViewController:twoVC];
UINavigationController *threeNav = [[UINavigationController alloc] initWithRootViewController:threeVC];
UINavigationController *fourNav = [[UINavigationController alloc] initWithRootViewController:fourVC];
UINavigationController *fiveNav = [[UINavigationController alloc] initWithRootViewController:fiveVC];
UINavigationController *sixNav = [[UINavigationController alloc] initWithRootViewController:sixVC];
设置标题
oneVC.tabBarItem.title = @”首页”;
twoVC.tabBarItem.title = @”第二页”;
threeVC.tabBarItem.title = @”第三页”;
fourVC.tabBarItem.title = @”第四页”;
fiveVC.tabBarItem.title = @”第五页”;
sixVC.tabBarItem.title = @”第六页”;
设置图片
显示图片原有颜色
//UIImageRenderingModeAlwaysOriginal
// 按原始的图片进行绘制(绘制出来是原来的颜色)
oneVC.tabBarItem.image = [[UIImage imageNamed:@”26-bandaid”] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
twoVC.tabBarItem.image = [[UIImage imageNamed:@”109-chicken”] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
threeVC.tabBarItem.image = [[UIImage imageNamed:@”11-clock”] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
fourVC.tabBarItem.image = [[UIImage imageNamed:@”11”] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
fiveVC.tabBarItem.image = [[UIImage imageNamed:@”110-bug”] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
sixVC.tabBarItem.image = [[UIImage imageNamed:@”04-squiggle”] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
设置选中的图片
oneVC.tabBarItem.selectedImage = [UIImage imageNamed:@”108-badge”];
twoVC.tabBarItem.selectedImage = [UIImage imageNamed:@”108-badge”];
threeVC.tabBarItem.selectedImage = [UIImage imageNamed:@”108-badge”];
fourVC.tabBarItem.selectedImage = [UIImage imageNamed:@”108-badge”];
fiveVC.tabBarItem.selectedImage = [UIImage imageNamed:@”108-badge”];
sixVC.tabBarItem.selectedImage = [UIImage imageNamed:@”108-badge”];
显示到tabBarController
需要添加到viewControllers数组中
self.viewControllers = @[oneNav,twoNav,threeNav,fourNav,fiveNav,sixNav];
设置bar的颜色
self.tabBar.barTintColor = [UIColor blueColor];
设置bar的填充色
self.tabBar.tintColor = [UIColor greenColor];
设置bar的背景图片
tabBar的高度 49
self.tabBar.backgroundImage = [UIImage imageNamed:@”tabBar”];
设置默认选中的页面
self.selectedIndex = 2;
设置tabBarItem上的 红色提示按钮
twoVC.tabBarItem.badgeValue = @”99”;
设置代理
self.delegate = self;
释放
[oneVC release];
[twoVC release];
[threeVC release];
[fourVC release];
[fiveVC release];
[sixVC release];
[oneNav release];
[twoNav release];
[threeNav release];
[fourNav release];
[fiveNav release];
[sixNav release];
}
# pragma mark – 代理方法