UITabBar
需要创建多个ViewController
import “AppDelegate.h”
import “FirstViewController.h”
import “TwoViewController.h”
import “ThreeViewController.h”
import “FourViewController.h”
import “FiveViewController.h”
import “sixViewController.h”
@interface AppDelegate ()
@end
@implementation AppDelegate
(void)dealloc
{
[_window release];
[super dealloc];
}(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];// 创建第一个视图控制器对象
FirstViewController *firstVC=[[FirstViewController alloc] init];
// 创建第一个naVC
UINavigationController *firstNaVC=[[UINavigationController alloc] initWithRootViewController:firstVC];
// 创建tabbar上的按钮及其内容
firstVC.tabBarItem=[[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:1000] autorelease];
firstVC.tabBarItem.badgeValue=@”+99”;// 创建第二个
TwoViewController *twoVC=[[TwoViewController alloc] init];
UINavigationController *twoNaVC=[[UINavigationController alloc] initWithRootViewController:twoVC];
twoVC.tabBarItem=[[[UITabBarItem alloc] initWithTitle:@”网易” image:[UIImage imageNamed:@”6.png”] selectedImage:[UIImage imageNamed:@”5.png”]] autorelease];// 创建第三个
ThreeViewController *threeVC=[[ThreeViewController alloc] init];
UINavigationController *threeNaVC=[[UINavigationController alloc] initWithRootViewController:threeVC];
threeVC.tabBarItem=[[[UITabBarItem alloc] initWithTitle:@”添加” image:[UIImage imageNamed:@”1.png”] tag:1002] autorelease];// 创建第四个
FourViewController *fourVC=[[FourViewController alloc] init];
UINavigationController *fourNaVC=[[UINavigationController alloc] initWithRootViewController:fourVC];
fourVC.tabBarItem=[[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1003] autorelease];// 创建第五个
FiveViewController *fiveVC=[[FiveViewController alloc] init];
UINavigationController *fiveNaVC=[[UINavigationController alloc] initWithRootViewController:fiveVC];
fiveVC.tabBarItem=[[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1004] autorelease];// 创建第六个
sixViewController *sixVC=[[sixViewController alloc] init];
UINavigationController *sixNaVC=[[UINavigationController alloc] initWithRootViewController:sixVC];
sixVC.tabBarItem=[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1005];
pragma mark 按钮创建好了,然后创建一个UITabbarController让所有的按钮显示出来
UITabBarController *tabVC=[[UITabBarController alloc] init];
// tabbarController通过一个数组来管理所有要显示出来的naVC
tabVC.viewControllers=@[firstNaVC,twoNaVC,threeNaVC,fourNaVC,fiveNaVC,sixNaVC];
self.window.rootViewController=tabVC;
// 对tabbar进行外观设置
tabVC.tabBar.translucent=NO;
// 背景颜色
tabVC.tabBar.barTintColor=[UIColor orangeColor];
// 点击之后的选中按钮的颜色
tabVC.tabBar.tintColor=[UIColor redColor];
// 设置代理人
tabVC.delegate=self;
// 点击进去在哪一个图标,从0开始的
tabVC.selectedIndex=0;
// 释放
[tabVC release];
[firstNaVC release];
[twoNaVC release];
[threeNaVC release];
[fourNaVC release];
[fiveVC release];
[sixNaVC release];
[firstVC release];
[twoVC release];
[threeVC release];
[fourVC release];
[fiveVC release];
[sixVC release];
return YES;
}
-(void)tabBarController:(UITabBarController )tabBarController didSelectViewController:(UIViewController )viewController{
// 点哪一个都带一个圈,不好看,不用
// viewController.tabBarItem.badgeValue=@”“;
viewController.tabBarItem.badgeValue=nil;
}