UITabBarController

#import "AppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FourthViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)dealloc {
    [_window release];
    [super dealloc];
}

- (void)change {
    [[UITabBar appearance] setBarTintColor:[UIColor greenColor]];
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    
    FirstViewController *firstVC = [[FirstViewController alloc] init];
    
    [firstVC.button addTarget:self action:@selector(change) forControlEvents:UIControlEventTouchUpInside];
    
    firstVC.tabBarItem.title = @"巴达";//设置显示文本
    firstVC.tabBarItem.badgeValue = @"富富";//设置显示角标
//    UIImage *image = [[UIImage imageNamed:@"iconfont-menfengguoda"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *image = [[UIImage imageNamed:@"iconfont-menfengguoda"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    firstVC.tabBarItem.image = image;//设置显示图片
    
    
    SecondViewController *secondVC = [[SecondViewController alloc] init];
    
    //第一个参数 为标签显示的文本
    //第二个参数 正常状态下显示的图片
    //第三个参数 选中状态下显示的图片
    //注意,图片想要正常显示,必须是png类型
    UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"秋香" image:[UIImage imageNamed:@"iconfont-buya"] selectedImage:[UIImage imageNamed:@"iconfont-3mquanciyaicon"]];
    
    //创建好标签之后指定为某一个视图控制器的标签
    secondVC.tabBarItem = item;
    [item release];
    
    ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
    
    //创建一个系统样式标签
    UITabBarItem *systemItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:101];
    thirdVC.tabBarItem = systemItem;
    [systemItem release];
    
    
    FourthViewController *fourthVC = [[FourthViewController alloc] init];
    
    //第一个参数 显示的文本
    //第二个参数 正常状态下显示的图片
    //第三个参数 标记值
    UITabBarItem *commomItem = [[UITabBarItem alloc] initWithTitle:@"洪荒" image:[UIImage imageNamed:@"iconfont-chaobotiemianicon"] tag:102];
    commomItem.badgeValue = @"1";
    fourthVC.tabBarItem = commomItem;
    [commomItem release];
    
    
    //创建标签视图控制器
    UITabBarController *tabbarController = [[UITabBarController alloc] init];
    
    //一键换肤,会员专用
    [[UITabBar appearance] setTintColor:[UIColor redColor]];
    
    
    
    
    
    //设置标签视图控制器需要管理的子视图控制器
    tabbarController.viewControllers = @[firstVC, secondVC, thirdVC, fourthVC];
    
    //设定标签栏选中的标签下标
    tabbarController.selectedIndex = 1;
    
    //指定window的根视图控制器为标签视图控制器
    self.window.rootViewController = tabbarController;
    
    //释放
    [firstVC release];
    [secondVC release];
    [thirdVC release];
    [fourthVC release];
    
    [tabbarController release];
    
    [self.window makeKeyAndVisible];
    return YES;
}

你可能感兴趣的:(UITabBarController)