123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- //
- // TabBarVC.m
- // jiaPei
- //
- // Created by apple on 15/11/26.
- // Copyright (c) 2015年 JCZ. All rights reserved.
- //
- #import "TabBarVC.h"
- #import "STButton.h"
- @interface TabBarVC ()
- {
- UIView* bar;
- NSMutableArray* btns;
- }
- @end
- @implementation TabBarVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.tabBar.hidden = YES;
- [self myInit];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- #pragma mark -
- -(void)myInit
- {
- CGFloat wid,hei,bd;
- _barHeight = hei = 45;
- bar = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height - hei , kSize.width, hei)];
- [bar setFrame:self.tabBar.frame];
- [bar setBackgroundColor:backGroundColor];
- [self.view addSubview:bar];
- [bar addSelfViewWithRect:CGRectMake(0, 0, kSize.width, 1) Color:lineColor];
-
- btns = [NSMutableArray array];
-
- wid = hei;
- int cnt = 4;
- NSArray* titles = @[@"考试",@"社区",@"发现",@"个人"];
- NSArray* images = @[@"tabbarImg1",@"tabbarImg2",@"tabbarImg3",@"tabbarImg4"];
- bd = ( kSize.width - wid * cnt)*1.0/(cnt + cnt) ;
- for (int i = 0; i<cnt; i++)
- {
- UIImage* img = [UIImage imageNamed:images[i]];
- STButton* btn = [[STButton alloc] initWithFrame:CGRectMake((bd+bd+wid)*(i%cnt)+bd, 0, wid, hei)];
- [btn setStyle:2];
- [btn setImage:[img tint:[UIColor grayColor]] withTitle:titles[i] Font:NormalFont forState:UIControlStateNormal];
- [btn setImage:[img tint:defGreen] withTitle:titles[i] Font:NormalFont forState:UIControlStateSelected];
- [btn setTitleColor:subTitleColor forState:UIControlStateNormal];
- [btn setTitleColor:defGreen forState:UIControlStateSelected];
- [btn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
- [btn.titleLabel setFont:[UIFont scaleSize:13]];
- [bar addSubview:btn];
- [btns addObject:btn];
- [btn setTag:i];
- }
- _currentBtn = btns[0];
- _currentBtn.selected = YES;
-
- _btnArray = [NSArray arrayWithArray:btns];
- }
- -(void)chooseBtn:(STButton*)sender
- {
- _currentBtn.selected = NO;
- [self setSelectedIndex:sender.tag];
- _currentBtn = btns[sender.tag];
- _currentBtn.selected = YES;
- }
- -(void)setHideBar:(BOOL)hideBar
- {
- _hideBar = hideBar;
-
- // static BOOL once = NO;
- // if (!once) {
- // once = YES;
- // [[UIApplication sharedApplication].keyWindow addSubview:bar];
- // }
- // [myDelegate.window sendSubviewToBack:bar];
-
- // [myDelegate.window addSubview:bar];
- [_sideVC.view addSubview:bar];
-
- CGRect frame = self.tabBar.frame;
- if (hideBar) {
- frame.origin.y = kSize.height;
- }
- [UIView animateWithDuration:.5 animations:^{
- bar.frame = frame;
- }];
- }
- @end
|