口袋优选

KBMorePicCell.m 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // KBMorePicCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/18.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBMorePicCell.h"
  9. #import "KBPicCollectionViewCell.h"
  10. #import "KBMorePicModel.h"
  11. @interface KBMorePicCell ()
  12. @property (nonatomic, strong) NSMutableArray *dataArr;
  13. @end
  14. @implementation KBMorePicCell
  15. - (void)awakeFromNib {
  16. [super awakeFromNib];
  17. // Initialization code
  18. }
  19. - (instancetype)initWithFrame:(CGRect)frame {
  20. self = [super initWithFrame:frame];
  21. if (self) {
  22. self.backgroundColor = [UIColor yhGrayColor];
  23. }
  24. return self;
  25. }
  26. - (void)setModelDatas:(NSArray *)dataArr {
  27. self.dataArr = [NSMutableArray arrayWithArray:dataArr];
  28. [self setUpImageView];
  29. }
  30. - (void)setUpImageView {
  31. for (int i = 0;i < self.dataArr.count; i++) {
  32. UIImageView *imageView = [[UIImageView alloc] init];
  33. imageView.contentMode = UIViewContentModeScaleAspectFit;
  34. imageView.clipsToBounds = YES;
  35. imageView.userInteractionEnabled = YES;
  36. imageView.backgroundColor = [UIColor whiteColor];
  37. imageView.tag = 1000 + i;
  38. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImages:)];
  39. [imageView addGestureRecognizer:tap];
  40. KBMorePicModel *model = self.dataArr[i];
  41. // [imageView sd_setImageWithURL:[NSURL URLWithString:model.img]];
  42. [imageView sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil];
  43. [self imageViewSetFrameWith:i imageView:imageView];
  44. [self.contentView addSubview:imageView];
  45. }
  46. }
  47. - (void)tapImages:(UITapGestureRecognizer *)tap {
  48. NSInteger index = tap.view.tag - 1000;
  49. if (self.delegate && [self.delegate respondsToSelector:@selector(YHMorePicCellDidSelectedItem:)]) {
  50. [self.delegate YHMorePicCellDidSelectedItem:index];
  51. }
  52. }
  53. - (void)imageViewSetFrameWith:(NSInteger)index imageView:(UIImageView *)imageView{
  54. CGFloat leftWidth = SCREEN_WIDTH*0.37;
  55. CGFloat leftHeight = leftWidth*19/14;
  56. CGFloat rightWidth = SCREEN_WIDTH-leftWidth-1;
  57. if (self.dataArr.count == 3) {
  58. switch (index) {
  59. case 0:
  60. {
  61. imageView.frame = CGRectMake(0, 0, leftWidth, leftHeight);
  62. break;
  63. }
  64. case 1:
  65. {
  66. imageView.frame = CGRectMake(leftWidth+1, 0, rightWidth, leftHeight*0.5);
  67. break;
  68. }
  69. case 2:
  70. {
  71. imageView.frame = CGRectMake(leftWidth+1, leftHeight*0.5+1, rightWidth, leftHeight*0.5-1);
  72. break;
  73. }
  74. default:
  75. break;
  76. }
  77. }else {
  78. switch (index) {
  79. case 0:
  80. {
  81. imageView.frame = CGRectMake(0, 0, leftWidth, leftHeight);
  82. break;
  83. }
  84. case 1:
  85. {
  86. imageView.frame = CGRectMake(leftWidth+1, 0, rightWidth, leftHeight*0.5);
  87. break;
  88. }
  89. case 2:
  90. {
  91. imageView.frame = CGRectMake(leftWidth+1, leftHeight*0.5+1, rightWidth/2, leftHeight*0.5-1);
  92. break;
  93. }
  94. case 3:
  95. {
  96. imageView.frame = CGRectMake((leftWidth+1)+(rightWidth/2)+1, leftHeight*0.5+1, rightWidth/2, leftHeight*0.5-1);
  97. break;
  98. }
  99. default:
  100. break;
  101. }
  102. }
  103. }
  104. @end