tabbarController

在AppDelegate.m中写

#import "AppDelegate.h"
#import "RootViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FouthViewController.h"
#import "FifthViewController.h"
#import "SixViewController.h"

@interface AppDelegate ()<UITabBarControllerDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor=[UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [self.window release];
    RootViewController *rootVC=[[RootViewController alloc] init];
    UINavigationController *naVC=[[UINavigationController alloc] initWithRootViewController:rootVC];

    //创建一个tabbar的按钮内容
    naVC.tabBarItem=[[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1000] autorelease];

    //提示有几条消息
    naVC.tabBarItem.badgeValue=@"23333";

    //创建第二个naVC
    SecondViewController *secVC=[[SecondViewController alloc] init];
    UINavigationController *secNAVC=[[UINavigationController alloc] initWithRootViewController:secVC];
    secNAVC.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"home" image:[UIImage imageNamed:@"1.jpg"] tag:1001];

    //创建第三个naVC
    ThirdViewController *thirdVC=[[ThirdViewController alloc] init];
    UINavigationController *thirdNAVC=[[UINavigationController alloc] initWithRootViewController:thirdVC];
    thirdNAVC.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"chat" image:[UIImage imageNamed:@"chat.jpg"] selectedImage:[UIImage imageNamed:@"f.jpg"]];

    //创建第四个
    FouthViewController *fouthVC=[[FouthViewController alloc] init];
    UINavigationController *fouthNAVC=[[UINavigationController alloc] initWithRootViewController:fouthVC];
    fouthNAVC.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"date" image:[UIImage imageNamed:@"date.png"] tag:1002];

    //创建第五个
    FifthViewController *fifthVC=[[FifthViewController alloc] init];
    UINavigationController *fifthNAVC=[[UINavigationController alloc] initWithRootViewController:fifthVC];
    fifthNAVC.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"type" image:[UIImage imageNamed:@"type.png"] tag:1003];
    //创建第六个
    SixViewController *sixVC=[[SixViewController alloc] init];
    UINavigationController *sixNAVC=[[UINavigationController alloc] initWithRootViewController:sixVC];
    sixNAVC.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"contact" image:[UIImage imageNamed:@"qq.png"] tag:1004];


    //创建tabbarController
    UITabBarController *tabVC=[[UITabBarController alloc] init];
    //设置tabVC管理的naVC
    tabVC.viewControllers=@[naVC,secNAVC,thirdNAVC,fouthNAVC,fifthNAVC,sixNAVC];
    //设置window的根视图控制器
    self.window.rootViewController=tabVC;

    //设置一下tabbar的外观
    //默认是透明的
    tabVC.tabBar.translucent=NO;

//    tabVC.tabBar.barTintColor=[UIColor yellowColor];
    tabVC.tabBar.tintColor=[UIColor redColor];

    //设置代理人
    tabVC.delegate=self;
   return YES;
}

这个方法相当于tab的点击方法

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
   viewController.tabBarItem.badgeValue=nil;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值