UI_UItabBarController

这里写图片描述

AppDelegate.m
#import "AppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FourthViewController.h"
#import "FifthViewController.h"
#import "SixthViewController.h"
@interface AppDelegate ()<UITabBarControllerDelegate>

@end

@implementation AppDelegate

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

// 实时监控选择的tabbar的索引.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    NSLog(@"%ld", tabBarController.selectedIndex);

    viewController.tabBarItem.badgeValue = nil;
    viewController.tabBarItem.badgeValue = @"";
}

- (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];

1.创建第一个tabbar.    
    FirstViewController *first = [[FirstViewController alloc] init];

    UINavigationController *firsthNC = [[UINavigationController alloc] initWithRootViewController:first];

    // 设定tabbarItem的内容.
    firsthNC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1000] autorelease];

2.创建第二个tabbar.    
    SecondViewController *second = [[SecondViewController alloc] init];
    UINavigationController *secondNC = [[UINavigationController alloc] initWithRootViewController:second];
    secondNC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"朋友圈" image:[UIImage imageNamed:@"1"] selectedImage:[UIImage imageNamed:@"3"]]autorelease];
    secondNC.tabBarItem.badgeValue = @"+1";

3.创建第三个tabbar.    
    ThirdViewController *third = [[ThirdViewController alloc] init];
    UINavigationController *thirdNC = [[UINavigationController alloc] initWithRootViewController:third];
    thirdNC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"分享" image:[UIImage imageNamed:@"2"] tag:1001] autorelease];
    thirdNC.tabBarItem.badgeValue = @"+99";

4.创建第四个tabbar.    
    FourthViewController *fourth = [[FourthViewController alloc] init];
    UINavigationController *fourthNC = [[UINavigationController alloc] initWithRootViewController:fourth];
    fourthNC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1002];

5.创建第五个tabbar.    
    FifthViewController *fifth = [[FifthViewController alloc] init];
    UINavigationController *fifthNC = [[UINavigationController alloc] initWithRootViewController:fifth];
    fifthNC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1003];

6.创建第六个tabbar.
    SixthViewController *sixth = [[SixthViewController alloc] init];
    UINavigationController *sixthNC = [[UINavigationController alloc] initWithRootViewController:sixth];
    sixthNC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:1004];

7.需要将这些tabBarController加入到数组中    
    // 设置数组.
    UITabBarController *tab = [[UITabBarController alloc] init];
    tab.viewControllers = @[firsthNC, secondNC, thirdNC, fourthNC, fifthNC,sixthNC];
    self.window.rootViewController = tab;

    // 设置外观tabbar
    tab.tabBar.translucent = NO;

    // 背景颜色.
    tab.tabBar.barTintColor = [UIColor magentaColor];
    // 选中后的颜色.
    tab.tabBar.tintColor = [UIColor blackColor];
    // 默认起始页.
    tab.selectedIndex = 2;

    tab.delegate = self;

    [first release];
    [firsthNC release];
    [tab release];
    [second release];
    [secondNC release];
    [third release];
    [thirdNC release];
    [fourth release];
    [fourthNC release];
    [fifth release];
    [fifthNC release];
    [sixth release];
    [sixthNC release];
    return YES;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值