CSFileExtensionViewForCell.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // CSFileExtensionViewForCell.m
  3. // zhuxun
  4. //
  5. // Created by winsoft on 17/6/16.
  6. //
  7. //
  8. #import "CSFileExtensionViewForCell.h"
  9. #import "CustomButton.h"
  10. #define ItemSizeW 32
  11. #define OnePageMaxItemCount 4
  12. @interface CSFileExtensionViewForCell()
  13. @property (nonatomic , strong) NSMutableArray *itemOpArrays;
  14. @property (nonatomic , strong) NSArray *itemArray;
  15. @end
  16. @implementation CSFileExtensionViewForCell
  17. - (NSMutableArray *)itemOpArrays
  18. {
  19. if (!_itemOpArrays) {
  20. _itemOpArrays = [NSMutableArray array];
  21. }
  22. return _itemOpArrays;
  23. }
  24. - (instancetype)initWithItmes:(NSArray *)items
  25. {
  26. if (self = [super init]) {
  27. self.backgroundColor = LineForSubLineViewColor;
  28. [self.itemOpArrays addObjectsFromArray:items];
  29. // UIScrollView *mainScrollView = [[UIScrollView alloc]init];
  30. // [self addSubview:mainScrollView];
  31. // self.mainScrollView = mainScrollView;
  32. _itemArray = items;
  33. for (int i = 0; i < self.itemOpArrays.count; i ++) {
  34. NSDictionary *itemDict = self.itemOpArrays[i];
  35. CustomButton *itemBtn = [[CustomButton alloc]initCustomBtnWithImageDirection:ImagePostionTop imageViewSize:CGSizeMake(ItemSizeW, ItemSizeW) imageLabelMargin:0 titleLabelFont:[UIFont systemFontOfSize:10] imageIcon:itemDict[@"icon"] selectIcon:nil title:itemDict[@"title"] btnWidth:ItemSizeW];
  36. [itemBtn addTarget:self action:@selector(extensionOp:) forControlEvents:UIControlEventTouchUpInside];
  37. itemBtn.tag = i;
  38. [self addSubview:itemBtn];
  39. }
  40. }
  41. return self;
  42. }
  43. - (void)extensionOp:(CustomButton *)btn
  44. {
  45. NSDictionary *item = self.itemArray[btn.tag];
  46. if (self.extensionOpBlock) {
  47. self.extensionOpBlock((ExtensionOP)[item[@"opType"] integerValue],nil);
  48. }
  49. }
  50. - (void)setDisable:(BOOL)disable
  51. {
  52. _disable = disable;
  53. if (disable) {
  54. for (CustomButton *customBtn in self.subviews) {
  55. if ([customBtn isKindOfClass:[CustomButton class]]) {
  56. customBtn.enabled = NO;
  57. [customBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
  58. }
  59. }
  60. }else{
  61. for (CustomButton *customBtn in self.subviews) {
  62. if ([customBtn isKindOfClass:[CustomButton class]]) {
  63. customBtn.enabled = YES;
  64. [customBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  65. }
  66. }
  67. }
  68. }
  69. - (void)layoutSubviews
  70. {
  71. [super layoutSubviews];
  72. // self.mainScrollView.frame = self.bounds;
  73. // CGFloat leftRightMargin = (self.frame.size.width - OnePageMaxItemCount * ItemSizeW) / (OnePageMaxItemCount * 2);
  74. CGFloat leftRightMargin = (self.frame.size.width - self.itemOpArrays.count * ItemSizeW) / (self.itemOpArrays.count * 2);
  75. self.contentSize = CGSizeMake(self.frame.size.width, self.frame.size.height);
  76. for (CustomButton *customBtn in self.subviews) {
  77. if ([customBtn isKindOfClass:[CustomButton class]]) {
  78. // CGFloat frameX = customBtn.tag * (leftRightMargin * 2 + ItemSizeW) + leftRightMargin;
  79. CGFloat frameX = customBtn.tag * (leftRightMargin * 2 + ItemSizeW) + leftRightMargin;
  80. CGFloat frameY = (self.frame.size.height - customBtn.customBtnHeight)/2.0f;
  81. CGFloat frameW = ItemSizeW;
  82. CGFloat frameH = customBtn.customBtnHeight;
  83. customBtn.frame = CGRectMake(frameX, frameY, frameW, frameH);
  84. }
  85. }
  86. }
  87. @end