新UI马甲包

FSBaseTopTableViewCell.m 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // FSBaseTopTableViewCell.m
  3. // FSScrollViewNestTableViewDemo
  4. //
  5. // Created by huim on 2017/5/23.
  6. // Copyright © 2017年 fengshun. All rights reserved.
  7. //
  8. #import "FSBaseTopTableViewCell.h"
  9. #import "FSLoopScrollView.h"
  10. #import "LDMorePicCollectionCell.h"
  11. #import "LDMorePicCollectionViewCell.h"
  12. #import "LDMorePicCollectionModel.h"
  13. @interface FSBaseTopTableViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
  14. @property (nonatomic, strong) NSMutableArray *dataArr;
  15. @end
  16. static NSInteger sumCell=0;
  17. @implementation FSBaseTopTableViewCell
  18. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  19. {
  20. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  21. if (self) {
  22. _imgv =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"super_back"]];
  23. _imgv.frame=CGRectMake(0,KStatusBarHeight, SCREEN_WIDTH, Fitsize(115));
  24. [self addSubview:_imgv];
  25. }
  26. return self;
  27. }
  28. - (void)layoutSubviews
  29. {
  30. [super layoutSubviews];
  31. }
  32. - (void)setModelDatas:(NSArray *)dataArr {
  33. self.dataArr = [NSMutableArray arrayWithArray:dataArr];
  34. if (self.dataArr.count !=0) {
  35. sumCell=self.dataArr.count;
  36. _collectionView=nil;
  37. for (UIView *view in self.subviews) {
  38. if ([view isKindOfClass:[UICollectionView class]]) {
  39. [view removeFromSuperview];
  40. }
  41. }
  42. [self addSubview:self.collectionView];
  43. [self.collectionView reloadData];
  44. }
  45. }
  46. #pragma mark -UICollectionViewDataSource
  47. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  48. if (self.dataArr==nil||self.dataArr.count==0) {
  49. return 0;
  50. }
  51. return self.dataArr.count;
  52. }
  53. - ( UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  54. LDMorePicCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"picCollectionViewCell" forIndexPath:indexPath];
  55. cell.backgroundColor =[UIColor YHColorWithHex:0xFFF3DE];
  56. if (!cell) {
  57. }
  58. // LDMorePicCollectionModel *model=self.dataArr[indexPath.row];
  59. // cell.titleLabel.text=model.name;
  60. // // [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@""]];
  61. // [cell.picImageView sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil];
  62. return cell;
  63. }
  64. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  65. return 0;
  66. }
  67. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  68. return 0;
  69. }
  70. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  71. if (self.delegate && [self.delegate respondsToSelector:@selector(YHMorePicCollectionCellDidSelectedItem:)]) {
  72. [self.delegate YHMorePicCollectionCellDidSelectedItem:indexPath.row];
  73. }
  74. }
  75. - (UICollectionView *)collectionView {
  76. if (!_collectionView) {
  77. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  78. if (sumCell==0) {
  79. sumCell=4;
  80. }
  81. NSInteger offHeight2=0;
  82. if (iPhone5) {
  83. offHeight2=10;
  84. }
  85. NSInteger Crow=1;
  86. NSInteger Coff=-1;
  87. NSInteger CrowItemSum=5;
  88. Coff=sumCell%CrowItemSum;
  89. if (Coff!=0) {
  90. CrowItemSum=4;
  91. Coff=sumCell%CrowItemSum;
  92. if (Coff!=0) {
  93. Coff=sumCell%3;
  94. CrowItemSum=3;
  95. if (Coff!=0) {
  96. CrowItemSum=5;
  97. }
  98. }
  99. }
  100. Crow=sumCell/CrowItemSum;
  101. if (Coff!=0) {
  102. Crow++;
  103. }
  104. float width=(SCREEN_WIDTH)/1.0f;
  105. flowLayout.itemSize = CGSizeMake((width-4)/CrowItemSum, SCREEN_WIDTH/4+offHeight2);
  106. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, KStatusBarHeight+Fitsize(115), width, (SCREEN_WIDTH/4+offHeight2)*Crow) collectionViewLayout:flowLayout];
  107. _collectionView.layer.masksToBounds=YES;
  108. _collectionView.backgroundColor=[UIColor YHColorWithHex:0xFFF3DE];
  109. _collectionView.delegate = self;
  110. _collectionView.dataSource = self;
  111. [_collectionView registerNib:[UINib nibWithNibName:@"LDMorePicCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"picCollectionViewCell"];
  112. }
  113. return _collectionView;
  114. }
  115. @end