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

#import "CustomImageBackView.h"

@implementation CustomImageBackView



- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {
        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)];
曹云霄's avatar
曹云霄 committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
            imageView.backgroundColor = kMainBlueColor;
            [self addSubview:imageView];
            if (i == 2) {
                //指示器
                UILabel *instruction = [[UILabel alloc] initWithFrame:CGRectMake(width-50, self.height-15, 50, 15)];
                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];
            }
        }
    }
    return self;
}

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#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;
            TOAttachmentEntity *entity = _imageArray[i];
            [imageView sd_setImageWithURL:[NSURL URLWithString:entity.fileUrl] placeholderImage:ReplaceImage];
        }
        if ([object isKindOfClass:[UILabel class]]) {
            UILabel *label = (UILabel *)object;
            label.text = [NSString stringWithFormat:@"共%ld张",_imageArray.count];
        }
    }
}






曹云霄's avatar
曹云霄 committed
62 63 64


@end