tabBar

- (void)viewDidLoad {

    [super viewDidLoad];

    

    

    [self creatVC];

    

    [self creatTabBar];

    

    NSLog(@"tabbar");

    

}


- (void)creatVC{

    

    StudentViewController * svc = [[StudentViewController alloc] init];

    TeachViewController *tvc = [[TeachViewController alloc] init];

    CarFirstPageViewController *cvc = [[CarFirstPageViewController alloc] init];

    RecruitViewController *rvc = [[RecruitViewController alloc] init];

    MineViewController *mvc = [[MineViewController alloc] init];

    

    UINavigationController *snc = [[UINavigationController alloc] initWithRootViewController:svc];

    UINavigationController *tnc = [[UINavigationController alloc] initWithRootViewController:tvc];

    UINavigationController *cnc = [[UINavigationController alloc] initWithRootViewController:cvc];

    UINavigationController *rnc = [[UINavigationController alloc] initWithRootViewController:rvc];

    UINavigationController *mnc = [[UINavigationController alloc] initWithRootViewController:mvc];

    

    self.viewControllers = [NSArray arrayWithObjects:snc, tnc, cnc, rnc, mnc, nil];

}



- (void)creatTabBar{

    

    UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"底部导航背景"]];

    iv.userInteractionEnabled = YES;

    [self.tabBar addSubview:iv];

    

    NSArray *titleArr = @[@"我的学员",@"教学",@"约车",@"招生",@"我的"];

    NSArray *imageArr = @[@"wodexueyuan",@"jiaoxue",@"zhaosheng",@"wode"];

    for (int i = 0; i < 5; i++) {

        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

        if (i == 2) {

            btn.frame = CGRectMake(ScreenWidth/2-25, -12, 50, 44);

            [btn setBackgroundImage:[UIImage imageNamed:@"yuechetubiao@2x"] forState:(UIControlStateNormal)];

            btn.tag = i;

            [btn setAdjustsImageWhenHighlighted:NO];

            [iv addSubview:btn];

            _label = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth/2-25, 32, 50, 15)];

            _label.text = titleArr[i];

            _label.textAlignment = NSTextAlignmentCenter;

            _label.textColor = RGB(153, 153, 153, 1);

            _label.font = [UIFont systemFontOfSize:11];

            _label.tag = 121;

            [iv addSubview:_label];

        }else{

            btn.frame = CGRectMake(ScreenWidth/5*i+(ScreenWidth/5-30)*0.5, 3, 30, 30);

            _label = [[UILabel alloc] initWithFrame:CGRectMake(-10, 29, 50, 15)];

            if (i > 2) {

                [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"tab_%@_unselected",imageArr[i-1]]] forState:UIControlStateNormal];

                [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"tab_%@_selected",imageArr[i-1]]] forState:UIControlStateSelected];

                _label.text = titleArr[i];

            }else{

                [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"tab_%@_unselected",imageArr[i]]] forState:UIControlStateNormal];

                [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"tab_%@_selected",imageArr[i]]] forState:UIControlStateSelected];

                _label.text = titleArr[i];

            }

            btn.tag = i;

            [iv addSubview:btn];

            

            _label.textAlignment = NSTextAlignmentCenter;

            _label.textColor = RGB(153, 153, 153, 1);

            _label.font = [UIFont systemFontOfSize:11];

            [btn addSubview:_label];

        }

        if (i == 1 || i == 4) {

            UIImageView *dotImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tishixiaohongdian"]];

            dotImage.backgroundColor = [UIColor clearColor];

            CGFloat x = btn.right;

            CGFloat y = btn.top;

            dotImage.frame =CGRectMake(x, y, 8,8);

            dotImage.tag = 1000+i;

            [iv addSubview:dotImage];

        }

        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];

        

        if (i == 0) {

            btn.selected = YES;

            _label.textColor = [UIColor colorWithRed:210/255.0 green:19/255.0 blue:32/255.0 alpha:1];

            _tmpBtn = btn;

            _tmpLabel = _label;

        }

    }

}


- (void)btnClick:(UIButton *)sender{

    if (_tmpBtn == sender) {

        return;

    }

    _tmpBtn.selected = NO;

    _tmpLabel.textColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1];

    if (sender.tag != 2) {

        sender.selected = YES;

        UILabel *label = (UILabel *)[sender.subviews lastObject];

        label.textColor = [UIColor colorWithRed:210/255.0 green:19/255.0 blue:32/255.0 alpha:1];

        _tmpLabel = label;

    }else{

        UILabel *label = (UILabel *)[self.tabBar viewWithTag:121];

        label.textColor = [UIColor colorWithRed:210/255.0 green:19/255.0 blue:32/255.0 alpha:1];

        _tmpLabel = label;

    }

    _tmpBtn = sender;

    

    self.selectedIndex = sender.tag;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值