| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- //
- // CSFileExtensionViewForCell.m
- // zhuxun
- //
- // Created by winsoft on 17/6/16.
- //
- //
- #import "CSFileExtensionViewForCell.h"
- #import "CustomButton.h"
- #define ItemSizeW 32
- #define OnePageMaxItemCount 4
- @interface CSFileExtensionViewForCell()
- @property (nonatomic , strong) NSMutableArray *itemOpArrays;
- @property (nonatomic , strong) NSArray *itemArray;
- @end
- @implementation CSFileExtensionViewForCell
- - (NSMutableArray *)itemOpArrays
- {
- if (!_itemOpArrays) {
- _itemOpArrays = [NSMutableArray array];
- }
-
- return _itemOpArrays;
-
- }
- - (instancetype)initWithItmes:(NSArray *)items
- {
- if (self = [super init]) {
-
- self.backgroundColor = LineForSubLineViewColor;
-
- [self.itemOpArrays addObjectsFromArray:items];
-
- // UIScrollView *mainScrollView = [[UIScrollView alloc]init];
- // [self addSubview:mainScrollView];
- // self.mainScrollView = mainScrollView;
-
-
- _itemArray = items;
-
- for (int i = 0; i < self.itemOpArrays.count; i ++) {
- NSDictionary *itemDict = self.itemOpArrays[i];
- 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];
-
- [itemBtn addTarget:self action:@selector(extensionOp:) forControlEvents:UIControlEventTouchUpInside];
- itemBtn.tag = i;
- [self addSubview:itemBtn];
- }
-
- }
-
- return self;
- }
- - (void)extensionOp:(CustomButton *)btn
- {
- NSDictionary *item = self.itemArray[btn.tag];
-
- if (self.extensionOpBlock) {
- self.extensionOpBlock((ExtensionOP)[item[@"opType"] integerValue],nil);
- }
- }
- - (void)setDisable:(BOOL)disable
- {
- _disable = disable;
-
- if (disable) {
-
-
- for (CustomButton *customBtn in self.subviews) {
- if ([customBtn isKindOfClass:[CustomButton class]]) {
-
- customBtn.enabled = NO;
-
- [customBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
- }
-
- }
- }else{
-
- for (CustomButton *customBtn in self.subviews) {
- if ([customBtn isKindOfClass:[CustomButton class]]) {
-
- customBtn.enabled = YES;
-
- [customBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- }
-
- }
- }
- }
- - (void)layoutSubviews
- {
- [super layoutSubviews];
-
- // self.mainScrollView.frame = self.bounds;
-
- // CGFloat leftRightMargin = (self.frame.size.width - OnePageMaxItemCount * ItemSizeW) / (OnePageMaxItemCount * 2);
-
- CGFloat leftRightMargin = (self.frame.size.width - self.itemOpArrays.count * ItemSizeW) / (self.itemOpArrays.count * 2);
-
-
- self.contentSize = CGSizeMake(self.frame.size.width, self.frame.size.height);
-
- for (CustomButton *customBtn in self.subviews) {
- if ([customBtn isKindOfClass:[CustomButton class]]) {
- // CGFloat frameX = customBtn.tag * (leftRightMargin * 2 + ItemSizeW) + leftRightMargin;
- CGFloat frameX = customBtn.tag * (leftRightMargin * 2 + ItemSizeW) + leftRightMargin;
- CGFloat frameY = (self.frame.size.height - customBtn.customBtnHeight)/2.0f;
- CGFloat frameW = ItemSizeW;
- CGFloat frameH = customBtn.customBtnHeight;
-
- customBtn.frame = CGRectMake(frameX, frameY, frameW, frameH);
- }
-
-
- }
-
-
- }
- @end
|