TabBarVC.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // TabBarVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 15/11/26.
  6. // Copyright (c) 2015年 JCZ. All rights reserved.
  7. //
  8. #import "TabBarVC.h"
  9. #import "STButton.h"
  10. @interface TabBarVC ()
  11. {
  12. UIView* bar;
  13. NSMutableArray* btns;
  14. }
  15. @end
  16. @implementation TabBarVC
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.tabBar.hidden = YES;
  20. [self myInit];
  21. }
  22. - (void)didReceiveMemoryWarning {
  23. [super didReceiveMemoryWarning];
  24. }
  25. #pragma mark -
  26. -(void)myInit
  27. {
  28. CGFloat wid,hei,bd;
  29. _barHeight = hei = 45;
  30. bar = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height - hei , kSize.width, hei)];
  31. [bar setFrame:self.tabBar.frame];
  32. [bar setBackgroundColor:backGroundColor];
  33. [self.view addSubview:bar];
  34. [bar addSelfViewWithRect:CGRectMake(0, 0, kSize.width, 1) Color:lineColor];
  35. btns = [NSMutableArray array];
  36. wid = hei;
  37. int cnt = 4;
  38. NSArray* titles = @[@"考试",@"社区",@"发现",@"个人"];
  39. NSArray* images = @[@"tabbarImg1",@"tabbarImg2",@"tabbarImg3",@"tabbarImg4"];
  40. bd = ( kSize.width - wid * cnt)*1.0/(cnt + cnt) ;
  41. for (int i = 0; i<cnt; i++)
  42. {
  43. UIImage* img = [UIImage imageNamed:images[i]];
  44. STButton* btn = [[STButton alloc] initWithFrame:CGRectMake((bd+bd+wid)*(i%cnt)+bd, 0, wid, hei)];
  45. [btn setStyle:2];
  46. [btn setImage:[img tint:[UIColor grayColor]] withTitle:titles[i] Font:NormalFont forState:UIControlStateNormal];
  47. [btn setImage:[img tint:defGreen] withTitle:titles[i] Font:NormalFont forState:UIControlStateSelected];
  48. [btn setTitleColor:subTitleColor forState:UIControlStateNormal];
  49. [btn setTitleColor:defGreen forState:UIControlStateSelected];
  50. [btn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
  51. [btn.titleLabel setFont:[UIFont scaleSize:13]];
  52. [bar addSubview:btn];
  53. [btns addObject:btn];
  54. [btn setTag:i];
  55. }
  56. _currentBtn = btns[0];
  57. _currentBtn.selected = YES;
  58. _btnArray = [NSArray arrayWithArray:btns];
  59. }
  60. -(void)chooseBtn:(STButton*)sender
  61. {
  62. _currentBtn.selected = NO;
  63. [self setSelectedIndex:sender.tag];
  64. _currentBtn = btns[sender.tag];
  65. _currentBtn.selected = YES;
  66. }
  67. -(void)setHideBar:(BOOL)hideBar
  68. {
  69. _hideBar = hideBar;
  70. // static BOOL once = NO;
  71. // if (!once) {
  72. // once = YES;
  73. // [[UIApplication sharedApplication].keyWindow addSubview:bar];
  74. // }
  75. // [myDelegate.window sendSubviewToBack:bar];
  76. // [myDelegate.window addSubview:bar];
  77. [_sideVC.view addSubview:bar];
  78. CGRect frame = self.tabBar.frame;
  79. if (hideBar) {
  80. frame.origin.y = kSize.height;
  81. }
  82. [UIView animateWithDuration:.5 animations:^{
  83. bar.frame = frame;
  84. }];
  85. }
  86. @end