[TwistedFate]TabBarController

TabBarController

创建控制器 创建导航控制器

//  创建控制器
FirstViewController *firstVC = [[FirstViewController alloc] init];

//  创建导航控制器
UINavigationController *firstNaVC = [[UINavigationController alloc] initWithRootViewController:firstVC];
    firstVC.view.backgroundColor = [UIColor redColor];

 SecondViewController *secondVC = [[SecondViewController alloc] init];
    secondVC.view.backgroundColor = [UIColor greenColor];
    UINavigationController *secondNaVC = [[UINavigationController alloc] initWithRootViewController:secondVC];

添加标题

firstVC.tabBarItem.title = @"首页";

添加图片

firstVC.tabBarItem.image = [UIImage imageNamed:@"01-refresh"];

非镂空图显示

//  按原始的图片进行绘制  绘制出来的与原来一样
secondVC.tabBarItem.image = [[UIImage imageNamed:@"11"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

设置选中的图片

//  设置选中的图片
    firstVC.tabBarItem.selectedImage = [UIImage imageNamed:@"02-redo"];

设置tabBarItem上的 红色提示按钮

secondVC.tabBarItem.badgeValue = @"22";

把视图添加进tabBarController

self.viewControllers = @[firstNaVC, secondNaVC];

设置bar的颜色

self.tabBar.barTintColor = [UIColor yellowColor];

设置bar的填充色

self.tabBar.tintColor = [UIColor orangeColor];

设置bar的背景图片

//  tabBar高度49
self.tabBar.backgroundImage = [UIImage imageNamed:@"tabBar"];

设置默认选中的页面

self.selectedIndex = 1;

设置代理

self.delegate = self;

代理方法

//  设置不允许点击
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{

    //  可以指定哪个控制器不让点击
    //  先取出 不让点击的控制器
    if (viewController == tabBarController.viewControllers[1]) {

        //  如果选中的控制器是你不想让用户点击的 那么返回NO
        return NO;

    }

    return YES;

}

//  选中页面时触发的方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{

    //  打印选中的索引
    NSLog(@"%ld",self.selectedIndex);

    //  选中时把红点去掉
    viewController.tabBarItem.badgeValue = nil;

}

//  控制more的代理方法
- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers{

    NSLog(@"将要开始编辑");

}

//
- (void)tabBarController:(UITabBarController *)tabBarController
willEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed{

    NSLog(@"将要结束编辑more");

}

- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed{

    NSLog(@"已经结束编辑more");

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值