UI_UITabBarController

建立控制器

    // 普通控制器
    GroupViewController *groupVC = [[GroupViewController alloc] init];
    SecondViewController *secondVC = [[SecondViewController alloc] init];
    ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
    FourthViewController *fourthVC = [[FourthViewController alloc] init];
    // 导航栏控制器
    UINavigationController *groupNC = [[UINavigationController alloc] initWithRootViewController:groupVC];
    UINavigationController *secondNC = [[UINavigationController alloc] initWithRootViewController:secondVC];
    UINavigationController *thirdNC = [[UINavigationController alloc] initWithRootViewController:thirdVC];
    UINavigationController *fourthNC = [[UINavigationController alloc] initWithRootViewController:fourthVC];```
@interface AppDelegate () <UITabBarControllerDelegate>
    // tabBarVC 控制器
    UITabBarController *tabBarVC = [[UITabBarController alloc] init];

    // 设置 tabBarVC 代理(先遵守协议)
    tabBarVC.delegate = self;

    // 设置 tabBar 默认选中的控制器
    tabBarVC.selectedIndex = 1;

    // 设置 tabBarVC 管理(包含)的控制器
    tabBarVC.viewControllers = @[groupNC, secondNC, thirdNC, fourthNC, uiVC1, uiVC2, uiVC3];
    // 自定义样式 tabBarItem(选中颜色)注意是那种控制器
    groupNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"活动" image:[UIImage imageNamed:@"activity"] selectedImage:[UIImage imageNamed:@"微信"]];
    // 显示右上角 小圈圈
    groupNC.tabBarItem.badgeValue = @"10";

    secondNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"影院" image:[UIImage imageNamed:@"cinema"] selectedImage:[UIImage imageNamed:@"通讯录"]];
    thirdNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"电影" image:[UIImage imageNamed:@"movie"] selectedImage:[UIImage imageNamed:@"发现"]];
    fourthNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我" image:[UIImage imageNamed:@"user"] selectedImage:[UIImage imageNamed:@"我"]];
    // 设置整个 tabBar
    // 颜色(和样式冲突)
    tabBarVC.tabBar.barTintColor = [UIColor yellowColor];
    // 样式(和颜色冲突)
//    tabBarVC.tabBar.barStyle = UIBarStyleBlack;
    // 字体颜色
    [tabBarVC.tabBar setTintColor:[UIColor greenColor]];
#pragma mark - 选择 tabBar 所控制的控制器,会执行的方法(每次都会执行)
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    NSInteger index =  [tabBarController.viewControllers indexOfObject:viewController];
    if (index == 3) {
        NSLog(@"four");
    }

    if (tabBarController.selectedIndex == 2) {
        NSLog(@"three");
    }

}

#pragma mark - 控制 tabBar 是否可以点击
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    return YES;
}
    // 获取到所有的 UINavigationBar(工程里面所有)
    [[UINavigationBar appearance] setBarTintColor:[UIColor purpleColor]];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值