| | |
| | | #import "PBExamineAddModel.h" |
| | | #import "PBPersonListView.h" |
| | | #import "PBPersonModel.h" |
| | | #import "MSSAutoresizeLabelFlowLayout.h" |
| | | #import "LBKeyWordLayout.h" |
| | | #import "KeyWordCell.h" |
| | | #import "PBPersonListCollectionViewCell.h" |
| | | #import "MSSAutoresizeLabelFlowConfig.h" |
| | | static NSString *const cellId = @"cellId"; |
| | | @interface PBPersonChooseTableViewCell()<UICollectionViewDataSource,UICollectionViewDelegate, MSSAutoresizeLabelFlowLayoutDataSource,MSSAutoresizeLabelFlowLayoutDelegate> |
| | | @interface PBPersonChooseTableViewCell()<UICollectionViewDataSource,UICollectionViewDelegate> |
| | | @property (nonatomic,strong) UICollectionView *collection; |
| | | @property (nonatomic,strong) NSMutableArray *data; |
| | | //@property (nonatomic,copy) selectedHandler handler; |
| | |
| | | @property (nonatomic, weak) UIView *collectionBg; |
| | | @property (nonatomic, assign) BOOL isLayout; |
| | | @property (nonatomic, assign) CGFloat height; |
| | | @property (strong, nonatomic) LBKeyWordLayout *layout; |
| | | |
| | | @end |
| | | @implementation PBPersonChooseTableViewCell |
| | | - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { |
| | |
| | | self.titleL = titleL; |
| | | self.personL = personL; |
| | | self.chooseBtn = chooseBtn; |
| | | |
| | | // UIView *collectionBg = [[UIView alloc] init]; |
| | | // collectionBg.backgroundColor = [UIColor yellowColor]; |
| | | // [self.contentView addSubview:collectionBg]; |
| | | // [collectionBg mas_makeConstraints:^(MASConstraintMaker *make) { |
| | | // make.top.equalTo(self.contentView).offset(53); |
| | | // make.left.equalTo(self.contentView).offset(100); |
| | | // make.right.equalTo(self.contentView).offset(-20); |
| | | // make.height.equalTo(@1); |
| | | // make.bottom.equalTo(self.contentView).offset(-15); |
| | | // }]; |
| | | self.layout = [[LBKeyWordLayout alloc] init]; |
| | | self.layout.estimatedItemSize = CGSizeMake(80, 30); |
| | | self.layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10); |
| | | |
| | | MSSAutoresizeLabelFlowLayout *layout = [[MSSAutoresizeLabelFlowLayout alloc]init]; |
| | | layout.delegate = self; |
| | | layout.dataSource = self; |
| | | self.collection = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout]; |
| | | self.collection = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.layout]; |
| | | self.collection.backgroundColor = [UIColor whiteColor]; |
| | | self.collection.allowsMultipleSelection = YES; |
| | | // self.collection.allowsMultipleSelection = YES; |
| | | self.collection.delegate = self; |
| | | self.collection.dataSource = self; |
| | | // self.collection.scrollEnabled = NO; |
| | | [self.collection registerClass:[PBPersonListCollectionViewCell class] forCellWithReuseIdentifier:cellId]; |
| | | [self.collection registerClass:[KeyWordCell class] forCellWithReuseIdentifier:@"KeyWordCell"]; |
| | | [self.contentView addSubview:self.collection]; |
| | | [self.collection mas_makeConstraints:^(MASConstraintMaker *make) { |
| | | // make.top.left.right.bottom.equalTo(collectionBg); |
| | |
| | | [self.collection layoutIfNeeded]; |
| | | if (self.examineAddModel.personArr.count > 0) { |
| | | [self.collection mas_updateConstraints:^(MASConstraintMaker *make) { |
| | | make.height.equalTo(@(76)); |
| | | // make.bottom.equalTo(self.contentView).offset(-(bottom)); |
| | | make.height.equalTo(@(70)); |
| | | }]; |
| | | }else { |
| | | [self.collection mas_updateConstraints:^(MASConstraintMaker *make) { |
| | | make.height.equalTo(@(1)); |
| | | // make.bottom.equalTo(self.contentView).offset(-(bottom)); |
| | | }]; |
| | | } |
| | | |
| | | self.titleL.text = examineAddModel.title; |
| | | // if (examineAddModel.personArr.count > 10) { |
| | | // self.totalNumberBtn.hidden = NO; |
| | | // }else { |
| | | // self.totalNumberBtn.hidden = YES; |
| | | // } |
| | | if (examineAddModel.personArr.count > 0) { |
| | | self.personL.textColor = PBColor(40, 58, 79); |
| | | self.personL.text = [NSString stringWithFormat:@"已选择%zd人", examineAddModel.personArr.count]; |
| | |
| | | self.personL.textColor = PBColor(204, 204, 204); |
| | | self.personL.text = examineAddModel.prompt; |
| | | } |
| | | |
| | | // if (self.data.count == 0) { |
| | | // [self.collectionBg mas_updateConstraints:^(MASConstraintMaker *make) { |
| | | // make.height.equalTo(@1); |
| | | // }]; |
| | | // } |
| | | |
| | | |
| | | // [self.collection setNeedsLayout]; |
| | | // [self.collection layoutIfNeeded]; |
| | | |
| | | // if (self.examineAddModel.personArr.count > 0) { |
| | | // NSLog(@"hhhhhhhhhhhhhhhhh-%f-%f",self.collection.contentSize.height,self.height); |
| | | // NSLog(@"wwwwwwwwwwwww-%f",self.collection.collectionViewLayout.collectionViewContentSize.height); |
| | | // [self.collection mas_updateConstraints:^(MASConstraintMaker *make) { |
| | | // make.height.equalTo(@(self.collection.collectionViewLayout.collectionViewContentSize.height)); |
| | | //// make.bottom.equalTo(self.contentView).offset(-(bottom)); |
| | | // }]; |
| | | // }else { |
| | | // [self.collection mas_updateConstraints:^(MASConstraintMaker *make) { |
| | | // make.height.equalTo(@(1)); |
| | | //// make.bottom.equalTo(self.contentView).offset(-(bottom)); |
| | | // }]; |
| | | // } |
| | | |
| | | |
| | | } |
| | | |
| | | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { |
| | | return 1; |
| | | } |
| | | |
| | | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { |
| | | // if (self.data.count > 10) { |
| | | // return 10; |
| | | // }else { |
| | | return self.data.count; |
| | | // } |
| | | return self.data.count; |
| | | } |
| | | |
| | | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { |
| | | PBPersonListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath]; |
| | | KeyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"KeyWordCell" forIndexPath:indexPath]; |
| | | cell.maxWidthConstraint.constant = CGRectGetWidth(collectionView.bounds) - self.layout.sectionInset.left - self.layout.sectionInset.right - cell.layoutMargins.left - cell.layoutMargins.right - 10; |
| | | cell.textLabel.numberOfLines = 1; |
| | | PBPersonModel *model = self.data[indexPath.item]; |
| | | [cell configCellWithTitle:model.RealName]; |
| | | cell.textLabel.text = model.RealName; |
| | | return cell; |
| | | } |
| | | |
| | | - (NSString *)titleForLabelAtIndexPath:(NSIndexPath *)indexPath { |
| | | PBPersonModel *model = self.data[indexPath.item]; |
| | | return model.RealName; |
| | | } |
| | | |
| | | - (void)layoutFinishWithNumberOfline:(NSInteger)number { |
| | | NSLog(@"===-=-=-=-=-=-=-=%zd",number); |
| | | // static NSInteger numberCount; |
| | | // if (numberCount == number) { |
| | | // return; |
| | | // } |
| | | // numberCount = number; |
| | | MSSAutoresizeLabelFlowConfig *config = [MSSAutoresizeLabelFlowConfig shareConfig]; |
| | | CGFloat h = config.contentInsets.top+config.contentInsets.bottom+config.itemHeight*number+config.lineSpace*(number-1); |
| | | self.height = h; |
| | | NSLog(@"mmmmmmmmmmmmmmmm-%f",h); |
| | | |
| | | // [self.contentView mas_updateConstraints:^(MASConstraintMaker *make) { |
| | | // make.bottom.equalTo(self.collection.mas_bottom).offset(15); |
| | | // }]; |
| | | // self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, h); |
| | | // [UIView animateWithDuration:0.2 animations:^{ |
| | | // self.collection.frame = self.bounds; |
| | | // }]; |
| | | |
| | | // [self.collection mas_updateConstraints:^(MASConstraintMaker *make) { |
| | | // make.height.equalTo(@(h)); |
| | | // }]; |
| | | // [self.contentView layoutIfNeeded]; |
| | | // CGFloat botton; |
| | | // if (self.examineAddModel.personArr.count > 10) { |
| | | // botton = 15.f + 32.f; |
| | | // self.totalNumberBtn.hidden = NO; |
| | | // [self.totalNumberBtn setTitle:[NSString stringWithFormat:@"查看全部%zd个%@", self.examineAddModel.personArr.count, self.examineAddModel.title] forState:UIControlStateNormal]; |
| | | // }else { |
| | | // botton = 15.f; |
| | | // self.totalNumberBtn.hidden = YES; |
| | | // } |
| | | // [self.collection mas_updateConstraints:^(MASConstraintMaker *make) { |
| | | // make.bottom.equalTo(self.contentView).offset(-(botton)); |
| | | // }]; |
| | | // CGFloat bottom; |
| | | // if (self.examineAddModel.personArr.count > 10) { |
| | | // self.totalNumberBtn.hidden = NO; |
| | | // bottom = 32 + 15; |
| | | // }else { |
| | | // self.totalNumberBtn.hidden = YES; |
| | | // bottom = 15; |
| | | // } |
| | | // NSLog(@"======%f",h); |
| | | // if (h <= 0) { |
| | | // h = 1.f; |
| | | // } |
| | | // self.examineAddModel.height = h; |
| | | // [self.collection mas_updateConstraints:^(MASConstraintMaker *make) { |
| | | // make.height.equalTo(@(h)); |
| | | // make.bottom.equalTo(self.contentView).offset(-(bottom)); |
| | | // }]; |
| | | // if (self.examineAddModel.height == 0) { |
| | | //// self.examineAddModel.height = h; |
| | | // if (self.ReLoadBlock) { |
| | | // self.ReLoadBlock(h); |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | - (void)awakeFromNib { |