CustomImageBackView.m 2.4 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//
//  CustomImageBackView.m
//  Lighting
//
//  Created by 曹云霄 on 2016/12/8.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "CustomImageBackView.h"

@implementation CustomImageBackView



15
- (void)awakeFromNib
曹云霄's avatar
曹云霄 committed
16
{
17 18 19 20
    [super awakeFromNib];
    CGFloat width = 150;
    CGFloat interval = 15;
    for (int i=0; i<3; i++) {
21
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i*width+i*interval, 0, width, width)];
22 23 24 25 26
        imageView.userInteractionEnabled = YES;
        imageView.tag = i;
        [imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(TapClickAction:)]];
        [self addSubview:imageView];
        if (i == 2) {
27
            UILabel *instruction = [[UILabel alloc] initWithFrame:CGRectMake(width-50, width-15, 50, 15)];
28 29 30 31 32 33
            instruction.text = @"共4张";
            instruction.font = [UIFont systemFontOfSize:10];
            instruction.textColor = [UIColor whiteColor];
            instruction.textAlignment = NSTextAlignmentCenter;
            instruction.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
            [imageView addSubview:instruction];
曹云霄's avatar
曹云霄 committed
34 35 36 37
        }
    }
}

38 39 40 41 42 43 44 45
#pragma mark - 更新View
- (void)setImageArray:(NSArray<TOAttachmentEntity *> *)imageArray
{
    _imageArray = imageArray;
    for (int i=0;i<self.subviews.count;i++) {
        id object = self.subviews[i];
        if ([object isKindOfClass:[UIImageView class]]) {
            UIImageView *imageView = (UIImageView *)object;
46 47 48
            TOAttachmentEntity *entity = [_imageArray objectAtIndex_opple:i];
            imageView.hidden = !entity;
            [imageView sd_setImageWithURL:[NSURL URLWithString:entity.fileUrl] placeholderImage:REPLACEIMAGE];
49 50 51 52 53 54 55 56
            if (i == 2) {
                for (id obj in imageView.subviews) {
                    if ([obj isKindOfClass:[UILabel class]]) {
                        UILabel *label = (UILabel *)obj;
                        label.text = [NSString stringWithFormat:@"共%ld张",_imageArray.count];
                    }
                }
            }
57 58 59 60
        }
    }
}

61 62 63 64 65 66 67
#pragma mark - 单击事件
- (void)TapClickAction:(UITapGestureRecognizer *)sender
{
    if ([self.delegate respondsToSelector:@selector(tapImageViewWithIndex:withCellIndex:)]) {
        [self.delegate tapImageViewWithIndex:sender.view.tag withCellIndex:self.indexPath];
    }
}
68 69 70 71




曹云霄's avatar
曹云霄 committed
72 73 74


@end