UITabBarController

1. UITabBarController———标签栏视图控制器

2. UITabBarController 分为3层结构: TabBarControlView TabBar custumContent

3. tabBar的重要属性以及用法: 

// 1. 自定义视图控制器
    OneViewController *oneVC = [[OneViewController alloc] init];
   
    TwoViewController *twoVC = [[TwoViewController alloc] init];
   
    ThreeViewController *threeVC = [[ThreeViewController alloc] init];
   
    FourViewController *fourVC = [[FourViewController alloc] init];
   
    FiveViewController *fiveVC = [[FiveViewController alloc] init];
   
    SixViewController *sixVC = [[SixViewController alloc] init];

    // 2. 创建一个UITabBarController
    UITabBarController *tabBarVC = [[UITabBarController alloc] init];
   
    // 3. 添加导航控制器
    UINavigationController *oneNC = [[UINavigationController alloc] initWithRootViewController:oneVC];
    UINavigationController *twoNC = [[UINavigationController alloc] initWithRootViewController:twoVC];
    UINavigationController *threeNC = [[UINavigationController alloc] initWithRootViewController:threeVC];
    UINavigationController *fourNC = [[UINavigationController alloc] initWithRootViewController:fourVC];
    UINavigationController *fiveNC = [[UINavigationController alloc] initWithRootViewController:fiveVC];
    UINavigationController *sixNC = [[UINavigationController alloc] initWithRootViewController:sixVC];

    // 4. 把控制器给UITabBarController去控制显示
    tabBarVC.viewControllers = @[oneNC, twoNC, threeNC, fourNC, fiveNC, sixNC];
    // 把UITabBarController设置成根视图控制器
    self.window.rootViewController = tabBarVC;

    // 更改bar的颜色
    tabBarVC.tabBar.barTintColor = [UIColor colorWithWhite:0.000 alpha:0.460];
    // 更改选中bar的颜色
    tabBarVC.tabBar.tintColor = [UIColor colorWithRed:1.000 green:0.553 blue:0.654 alpha:1.000];

    // 添加tabBar的背景图片
    [tabBarVC.tabBar setBackgroundImage:[UIImage imageNamed:@"tabBar"]];
   
    // tabBarItems的高度为49
    // 添加tabBarItems图片, 必须是PNG格式的, 图片的大小必须是30*30以内的. 图片必须是镂空图
    oneNC.tabBarItem.image = [UIImage imageNamed:@"01-refresh"];
    twoNC.tabBarItem.image = [UIImage imageNamed:@"02-redo"];
    threeNC.tabBarItem.image = [UIImage imageNamed:@"03-loopback"];
    fourNC.tabBarItem.image = [UIImage imageNamed:@"04-squiggle"];
    fiveNC.tabBarItem.image = [UIImage imageNamed:@"05-shuffle"];
    sixNC.tabBarItem.image = [UIImage imageNamed:@"06-magnifying-glass"];

    // 添加标题
    oneNC.tabBarItem.title = @"首页";
    twoNC.tabBarItem.title = @"two";
    threeNC.tabBarItem.title = @"three";
    fourNC.tabBarItem.title = @"four";
    fiveNC.tabBarItem.title = @"five";
    sixNC.tabBarItem.title = @"six";

    // 添加点点击后更换的图片
    oneNC.tabBarItem.selectedImage = [UIImage imageNamed:@"02-redo"];
    twoNC.tabBarItem.selectedImage = [UIImage imageNamed:@"06-magnifying-glass"];
    threeNC.tabBarItem.selectedImage = [UIImage imageNamed:@"04-squiggle"];
    fourNC.tabBarItem.selectedImage = [UIImage imageNamed:@"01-refresh"];
    fiveNC.tabBarItem.selectedImage = [UIImage imageNamed:@"03-loopback"];
    sixNC.tabBarItem.selectedImage = [UIImage imageNamed:@"05-shuffle"];

    // 左上角的小红标, 传入的是字符串
    oneNC.tabBarItem.badgeValue = @"99+";
    twoNC.tabBarItem.badgeValue = @"10";
    threeNC.tabBarItem.badgeValue = @"new";
   
    // 让tabBar默认选中第二个页面, 索引从0开始
    tabBarVC.selectedIndex = 1;

    // 设置代理
    tabBarVC.delegate = self;

主要使用的代理方法:
// 选中后触发的方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    NSLog(@"这是第%ld个界面", tabBarController.selectedIndex);
   
    // 代理方法应用场景: 点击回来, 刷新数据, 更改界面
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值