JXTopSiftJobView.m 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. //
  2. // JXTopSiftJobView.m
  3. // shiku_im
  4. //
  5. // Created by MacZ on 16/5/19.
  6. // Copyright (c) 2016年 Reese. All rights reserved.
  7. //
  8. #import "JXTopSiftJobView.h"
  9. #define ITEMBTN_WIDTH (self.frame.size.width-50)/3
  10. #define ITEMBTN_HEIGHT 40
  11. @interface JXTopSiftJobView (){
  12. CGFloat _moreParaBtnWidth;
  13. }
  14. @property (nonatomic, assign) CGFloat itemBtnWidth;
  15. @property (nonatomic, strong) NSMutableArray * btnArray;
  16. @end
  17. @implementation JXTopSiftJobView
  18. - (void)dealloc
  19. {
  20. // [_dataArray release];
  21. _dataArray = nil;
  22. // [_paraDataArray release];
  23. _paraDataArray = nil;
  24. _btnArray = nil;
  25. // [super dealloc];
  26. }
  27. - (instancetype)initWithFrame:(CGRect)frame{
  28. self = [super initWithFrame:frame];
  29. if(self){
  30. self.backgroundColor = [UIColor whiteColor];
  31. }
  32. return self;
  33. }
  34. - (void)setDataArray:(NSArray *)dataArray {
  35. if(_dataArray != dataArray){
  36. _dataArray = dataArray;
  37. _btnArray = [[NSMutableArray alloc] init];
  38. if (self.isShowMoreParaBtn) {
  39. //更多筛选条件按钮
  40. UIButton *moreParaBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.frame.size.width-50, 0, 50, ITEMBTN_HEIGHT)];
  41. [moreParaBtn setImage:[UIImage imageNamed:@"ic_filter_display"] forState:UIControlStateNormal];
  42. [moreParaBtn addTarget:self action:@selector(moreParaBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  43. [self addSubview:moreParaBtn];
  44. UIView *leftVerticalLine = [[UIView alloc] initWithFrame:CGRectMake(0,0,LINE_WH,ITEMBTN_HEIGHT)];
  45. leftVerticalLine.backgroundColor = THE_LINE_COLOR;
  46. [moreParaBtn addSubview:leftVerticalLine];
  47. }
  48. self.itemBtnWidth = 0;
  49. if (self.isShowMoreParaBtn) {
  50. self.itemBtnWidth = (self.frame.size.width-50)/self.dataArray.count;
  51. }else {
  52. self.itemBtnWidth = self.frame.size.width / self.dataArray.count;
  53. }
  54. [_btnArray removeAllObjects];
  55. for (int i=0; i<_dataArray.count; i++) {
  56. UIButton *itemBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.itemBtnWidth*i, 0, self.itemBtnWidth, ITEMBTN_HEIGHT)];
  57. itemBtn.tag = i+100;
  58. [itemBtn setTitle:_dataArray[i] forState:UIControlStateNormal];
  59. itemBtn.titleLabel.font = SYSFONT(16);
  60. [itemBtn setTitleColor:self.titleNormalColor ? self.titleNormalColor : [UIColor lightGrayColor] forState:UIControlStateNormal];
  61. [itemBtn setTitleColor:self.titleSelectedColor ? self.titleSelectedColor : [UIColor grayColor] forState:UIControlStateSelected];
  62. [itemBtn addTarget:self action:@selector(itemBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  63. [self addSubview:itemBtn];
  64. [_btnArray addObject:itemBtn];
  65. if (i == _preferred) {
  66. itemBtn.selected = YES;
  67. }
  68. }
  69. if (self.isShowBottomLine) {
  70. //底部滑动线条
  71. _bottomSlideLine = [[UIView alloc] initWithFrame:CGRectMake(0, ITEMBTN_HEIGHT-2, self.itemBtnWidth, 2)];
  72. _bottomSlideLine.backgroundColor = THEMECOLOR;
  73. [self addSubview:_bottomSlideLine];
  74. }
  75. [self resetBottomLineIndex:_preferred];
  76. }
  77. }
  78. -(void)setPreferred:(NSUInteger)preferred{
  79. if(_preferred != preferred){
  80. _preferred = preferred;
  81. }
  82. }
  83. - (void)moveBottomSlideLine:(CGFloat)offsetX{
  84. CGRect frame = _bottomSlideLine.frame;
  85. frame.origin.x = offsetX/(JX_SCREEN_WIDTH*2)*self.itemBtnWidth*2;
  86. _bottomSlideLine.frame = frame;
  87. }
  88. - (void)resetBottomLineIndex:(NSUInteger)index{
  89. if (index >= _dataArray.count) {
  90. return;
  91. }
  92. UIButton * btn = _btnArray[index];
  93. CGRect frame = _bottomSlideLine.frame;
  94. frame.origin.x = btn.frame.origin.x;
  95. _bottomSlideLine.frame = frame;
  96. for (UIButton * button in _btnArray) {
  97. button.selected = NO;
  98. }
  99. btn.selected = YES;
  100. }
  101. - (void)itemBtnClick:(UIButton *)btn{
  102. if (btn.selected) { //重复点击按钮
  103. return;
  104. }else{
  105. [self.delegate performSelector:@selector(topItemBtnClick:) withObject:btn];
  106. }
  107. for (UIView *view in self.subviews) {
  108. if (view.tag >=100 && view.tag <= 102) {
  109. UIButton *tempBtn = (UIButton *)view;
  110. if (tempBtn.tag == btn.tag) {
  111. tempBtn.selected = YES;
  112. }else{
  113. tempBtn.selected = NO;
  114. }
  115. }
  116. }
  117. //移动底部线条
  118. [UIView animateWithDuration:0.2 animations:^{
  119. CGRect frame = _bottomSlideLine.frame;
  120. frame.origin.x = btn.frame.origin.x;
  121. _bottomSlideLine.frame = frame;
  122. }];
  123. }
  124. //显示更多筛选条件
  125. - (void)moreParaBtnClick:(UIButton *)btn{
  126. if (_moreParaView == nil) {
  127. [self initMoreParaView];
  128. }
  129. [self showMoreParaView:YES];
  130. }
  131. //初始化更多筛选条件面板
  132. - (void)initMoreParaView{
  133. }
  134. - (void)hideMoreParaBtnClick:(UIButton *)btn{
  135. [self showMoreParaView:NO];
  136. }
  137. //条件按钮点击
  138. - (void)paraItemBtnClick:(UIButton *)btn{
  139. [UIView animateWithDuration:0.5 animations:^{
  140. btn.imageView.transform = CGAffineTransformMakeRotation(M_PI);
  141. }];
  142. _paraSelIndex = btn.tag;
  143. [self.delegate performSelector:@selector(paraItemBtnClick:) withObject:btn];
  144. }
  145. //显示、隐藏更多筛选条件面板
  146. - (void)showMoreParaView:(BOOL)show{
  147. CGRect frame = _moreParaView.frame;
  148. if (show) {
  149. frame.origin.x = 0;
  150. }else{
  151. frame.origin.x = self.frame.size.width;
  152. }
  153. [UIView animateWithDuration:0.3 animations:^{
  154. _moreParaView.frame = frame;
  155. }];
  156. }
  157. //scrollView滑动结束,改变顶部item按钮选中状态
  158. - (void)resetItemBtnWith:(CGFloat)offsetX{
  159. for (UIView *view in self.subviews) {
  160. if (view.tag >= 100 && view.tag <= 102) {
  161. UIButton *btn = (UIButton *)view;
  162. if (view.tag == offsetX/JX_SCREEN_WIDTH+100) {
  163. btn.selected = YES;
  164. }else{
  165. btn.selected = NO;
  166. }
  167. }
  168. }
  169. }
  170. //重置选中的参数按钮状态
  171. - (void)resetSelParaBtnTransform{
  172. for (UIView *view in _moreParaView.subviews) {
  173. if (view.tag == _paraSelIndex) {
  174. UIButton *btn = (UIButton *)view;
  175. btn.imageView.transform = CGAffineTransformIdentity;
  176. }
  177. }
  178. }
  179. //选中某个筛选条件后改变按钮文案
  180. - (void)resetWithIndex:(NSInteger)index itemId:(int)itemId itemValue:(NSString *)value{
  181. for (UIView *view in _moreParaView.subviews) {
  182. if (view.tag == index) {
  183. UIButton *btn = (UIButton *)view;
  184. if (itemId == 0) {
  185. [btn setTitle:Localized(@"JXTopSiftJobView_Default") forState:UIControlStateNormal];
  186. btn.selected = NO;
  187. }else{
  188. [btn setTitle:value forState:UIControlStateNormal];
  189. btn.selected = YES;
  190. }
  191. [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -btn.imageView.frame.size.width, 0, btn.imageView.frame.size.width)];
  192. [btn setImageEdgeInsets:UIEdgeInsetsMake(0, btn.titleLabel.frame.size.width, 0, -btn.titleLabel.frame.size.width)];
  193. }
  194. }
  195. }
  196. //选中薪水筛选条件后改变按钮文案
  197. - (void)resetWithIndex:(NSInteger)index min:(NSInteger)min max:(NSInteger)max{
  198. for (UIView *view in _moreParaView.subviews) {
  199. if (view.tag == index) {
  200. UIButton *btn = (UIButton *)view;
  201. if (min == 0 && max == 0) {
  202. [btn setTitle:Localized(@"JXTopSiftJobView_FaceToFace") forState:UIControlStateNormal];
  203. btn.selected = NO;
  204. }else{
  205. if (min >= 1000 && max >= 1000) {
  206. min = min/1000;
  207. max = max/1000;
  208. [btn setTitle:[NSString stringWithFormat:@"%ldk-%ldk",min,max] forState:UIControlStateNormal];
  209. }else{
  210. [btn setTitle:[NSString stringWithFormat:@"%ld-%ld",min,max] forState:UIControlStateNormal];
  211. }
  212. btn.selected = YES;
  213. }
  214. [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -btn.imageView.frame.size.width, 0, btn.imageView.frame.size.width)];
  215. [btn setImageEdgeInsets:UIEdgeInsetsMake(0, btn.titleLabel.frame.size.width, 0, -btn.titleLabel.frame.size.width)];
  216. }
  217. }
  218. }
  219. - (void)resetAllParaBtn{
  220. for (UIView *view in _moreParaView.subviews) {
  221. if (view.tag >= 200 && view.tag <= 202) {
  222. UIButton *btn = (UIButton *)view;
  223. btn.imageView.transform = CGAffineTransformIdentity;
  224. btn.selected = NO;
  225. [btn setTitle:[_paraDataArray objectAtIndex:btn.tag-200] forState:UIControlStateNormal];
  226. [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -btn.imageView.frame.size.width, 0, btn.imageView.frame.size.width)];
  227. [btn setImageEdgeInsets:UIEdgeInsetsMake(0, btn.titleLabel.frame.size.width, 0, -btn.titleLabel.frame.size.width)];
  228. }
  229. }
  230. }
  231. /*
  232. // Only override drawRect: if you perform custom drawing.
  233. // An empty implementation adversely affects performance during animation.
  234. - (void)drawRect:(CGRect)rect {
  235. // Drawing code
  236. }
  237. */
  238. @end