猎豆优选

ComprehensiveView.m 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // ComprehensiveView.m
  3. // YouHuiProject
  4. //
  5. // Created by liuxueli on 2019/1/4.
  6. // Copyright © 2019 kuxuan. All rights reserved.
  7. //
  8. #import "ComprehensiveView.h"
  9. @implementation ComprehensiveView
  10. -(instancetype)initWithFrame:(CGRect)frame CompreensiveArray:(NSArray *)arr
  11. {
  12. self =[super initWithFrame:frame];
  13. if (self) {
  14. self.backgroundColor =[UIColor whiteColor];
  15. [self initSubViews:arr];
  16. }
  17. return self;
  18. }
  19. -(void)initSubViews:(NSArray *)array
  20. {
  21. self.btnArray =[NSMutableArray array];
  22. for (int i =0; i<array.count; i++) {
  23. NSDictionary *dics =array[i];
  24. UIButton *button =[[UIButton alloc]initWithFrame:CGRectMake(0, i*40,SCREEN_WIDTH, 39.5)];
  25. [button setTitle:dics[@"title"] forState:UIControlStateNormal];
  26. [button setTitleColor:[UIColor YHColorWithHex:0x666666] forState:UIControlStateNormal];
  27. button.titleLabel.font =[UIFont systemFontOfSize:13];
  28. [self addSubview:button];
  29. button.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;
  30. button.titleEdgeInsets=UIEdgeInsetsMake(0, 34, 0, 0);
  31. button.tag = [dics[@"type"] integerValue]*100;
  32. [button addTarget:self action:@selector(selectSortType:) forControlEvents:UIControlEventTouchUpInside];
  33. if (self.selectDic.allKeys == 0) {
  34. if (i == 0) {
  35. [button setTitleColor:[UIColor YHColorWithHex:0xFF5A4A] forState:UIControlStateNormal];
  36. self.selectDic = dics;
  37. UIImageView *rightImg =[[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-45, 15, 13, 8)];
  38. rightImg.tag =1254;
  39. [rightImg setImage:[UIImage imageNamed:@"duihao-2"]];
  40. [self addSubview:rightImg];
  41. }
  42. }
  43. [self.btnArray addObject:button];
  44. UIView *lineviw =[[UIView alloc]initWithFrame:CGRectMake(0, i*40+39.5, SCREEN_WIDTH, 0.5)];
  45. lineviw.backgroundColor =[UIColor lineColor];
  46. [self addSubview:lineviw];
  47. }
  48. }
  49. -(void)setSelectDic:(NSDictionary *)selectDic
  50. {
  51. _selectDic = selectDic;
  52. UIImageView *imgv =[self viewWithTag:1254];
  53. for (int i =0; i<self.btnArray.count; i++) {
  54. UIButton *button =self.btnArray[i];
  55. if ([selectDic[@"type"] integerValue] == button.tag/100) {
  56. [button setTitleColor:[UIColor YHColorWithHex:0xFF5A4A] forState:UIControlStateNormal];
  57. imgv.frame=CGRectMake(SCREEN_WIDTH-45, 15+i*40, 13, 8);
  58. }else{
  59. [button setTitleColor:[UIColor YHColorWithHex:0x666666] forState:UIControlStateNormal];
  60. }
  61. }
  62. }
  63. -(void)selectSortType:(UIButton *)btn
  64. {
  65. if ([self.delegate respondsToSelector:@selector(selectWithBtn:)]) {
  66. [self.delegate selectWithBtn:btn];
  67. }
  68. }
  69. @end