123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- //
- // KBMorePicCell.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/1/18.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBMorePicCell.h"
- #import "KBPicCollectionViewCell.h"
- #import "KBMorePicModel.h"
- @interface KBMorePicCell ()
- @property (nonatomic, strong) NSMutableArray *dataArr;
- @end
- @implementation KBMorePicCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- self.backgroundColor = [UIColor yhGrayColor];
- }
- return self;
- }
- - (void)setModelDatas:(NSArray *)dataArr {
- self.dataArr = [NSMutableArray arrayWithArray:dataArr];
- [self setUpImageView];
- }
- - (void)setUpImageView {
-
- for (int i = 0;i < self.dataArr.count; i++) {
- UIImageView *imageView = [[UIImageView alloc] init];
- imageView.contentMode = UIViewContentModeScaleAspectFit;
- imageView.clipsToBounds = YES;
- imageView.userInteractionEnabled = YES;
- imageView.backgroundColor = [UIColor whiteColor];
- imageView.tag = 1000 + i;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImages:)];
- [imageView addGestureRecognizer:tap];
-
- KBMorePicModel *model = self.dataArr[i];
- // [imageView sd_setImageWithURL:[NSURL URLWithString:model.img]];
- [imageView sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil];
- [self imageViewSetFrameWith:i imageView:imageView];
- [self.contentView addSubview:imageView];
-
- }
- }
- - (void)tapImages:(UITapGestureRecognizer *)tap {
- NSInteger index = tap.view.tag - 1000;
- if (self.delegate && [self.delegate respondsToSelector:@selector(YHMorePicCellDidSelectedItem:)]) {
- [self.delegate YHMorePicCellDidSelectedItem:index];
- }
- }
- - (void)imageViewSetFrameWith:(NSInteger)index imageView:(UIImageView *)imageView{
-
- CGFloat leftWidth = SCREEN_WIDTH*0.37;
- CGFloat leftHeight = leftWidth*19/14;
-
- CGFloat rightWidth = SCREEN_WIDTH-leftWidth-1;
-
- if (self.dataArr.count == 3) {
- switch (index) {
- case 0:
- {
- imageView.frame = CGRectMake(0, 0, leftWidth, leftHeight);
-
- break;
- }
- case 1:
- {
- imageView.frame = CGRectMake(leftWidth+1, 0, rightWidth, leftHeight*0.5);
-
- break;
- }
- case 2:
- {
- imageView.frame = CGRectMake(leftWidth+1, leftHeight*0.5+1, rightWidth, leftHeight*0.5-1);
-
- break;
- }
- default:
- break;
- }
- }else {
- switch (index) {
- case 0:
- {
- imageView.frame = CGRectMake(0, 0, leftWidth, leftHeight);
-
-
- break;
- }
- case 1:
- {
- imageView.frame = CGRectMake(leftWidth+1, 0, rightWidth, leftHeight*0.5);
-
- break;
- }
- case 2:
- {
- imageView.frame = CGRectMake(leftWidth+1, leftHeight*0.5+1, rightWidth/2, leftHeight*0.5-1);
-
- break;
- }
- case 3:
- {
- imageView.frame = CGRectMake((leftWidth+1)+(rightWidth/2)+1, leftHeight*0.5+1, rightWidth/2, leftHeight*0.5-1);
- break;
- }
- default:
- break;
- }
- }
-
-
-
- }
- @end
|