UI_UITabViewController

Day 13


AppDelegate.m

// 2. 设置根视图控制器
    // 2.1 把将要添加到标签控制器中的视图控制器都创建
    WeChatViewController *weChatVC = [[WeChatViewController new] autorelease];
    weChatVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"WeChat" image:[UIImage imageNamed:@"item_normal@2x.png"] tag:101] autorelease];

    ContactsViewController *contactsVC = [[ContactsViewController new] autorelease];
    contactsVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:100] autorelease];


    DiscoverViewController *discoverVC = [[DiscoverViewController new] autorelease];
    discoverVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"Discover" image:[UIImage imageNamed:@"item_normal@2x.png"] selectedImage:[UIImage imageNamed:@"item_selected@2x.png"]] autorelease];


    MeViewController *meVC = [[MeViewController new] autorelease];
    meVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:102] autorelease];
// 2.2 创建标签控制器
    UITabBarController *rootTBC = [[[UITabBarController alloc] init] autorelease];
    // 给标签控制器添加子控制器
    rootTBC.viewControllers = @[weChatVC, contactsVC, discoverVC, meVC];

    // 2.3 设置根视图控制器
    self.window.rootViewController = rootTBC;

    // 3. 设置UITabBar的一些常用属性
    // 3.1 选中的渲染颜色
    rootTBC.tabBar.tintColor = [UIColor redColor];

    // 3.2 设置整体渲染颜色
    rootTBC.tabBar.barTintColor = [UIColor purpleColor];

    // 3.3 设置背景图片
    rootTBC.tabBar.backgroundImage = [UIImage imageNamed:@"tab_bar_bg.png"];

// 3代表有3条新消息传来(即角标)
contactsVC.tabBarItem.badgeValue = @"3";

// 设置代理后,实现协议UITabBarControllerDelegate中的方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    NSLog(@"%@", viewController);
    // 点击哪个控制器,上面的提示信息就消失
    viewController.tabBarItem.badgeValue = nil;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值