ZZPhotoPickerCell.m 2.44 KB
//
//  ZZPhotoPickerCell.m
//  ZZFramework
//
//  Created by Yuan on 15/7/7.
//  Copyright (c) 2015年 zzl. All rights reserved.
//

#import "ZZPhotoPickerCell.h"

@implementation ZZPhotoPickerCell
{
    UIImageView *img_play;
}
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        CGFloat photoSize = ([UIScreen mainScreen].bounds.size.width - 3) / 4;
        
        _photo = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, photoSize, photoSize)];
        
        _photo.layer.masksToBounds = YES;
        
        _photo.contentMode = UIViewContentModeScaleAspectFill;
        
        [self.contentView addSubview:_photo];
        
        
        CGFloat picViewSize = ([UIScreen mainScreen].bounds.size.width - 3) / 4;
        
        CGFloat btnSize = picViewSize / 4;
        
        _selectBtn = [[UIButton alloc]initWithFrame:CGRectMake(picViewSize - btnSize - 5, 5, btnSize, btnSize)];
        
        [self.contentView addSubview:_selectBtn];
        
        CGFloat imgSize = picViewSize / 3;
        
        img_play = [[UIImageView alloc]initWithFrame:CGRectMake((picViewSize-imgSize)/2, (picViewSize-imgSize)/2, imgSize, imgSize)];
        img_play.hidden = YES;
        [self.contentView addSubview:img_play];
        
    }
    return self;
}

- (void)setModel:(id)model
{
    _model = model;
}

//记录按钮选中和非选中的状态
-(void)selectBtnStage:(NSMutableArray *)selectArray existence:(ZZPhoto *)photo
{
    for (ZZPhoto *photos in selectArray) {
        if ([photos.asset isEqual:photo.asset]) {
            _selectBtn.selected = YES;
            [_selectBtn setImage:Pic_Btn_Selected forState:UIControlStateNormal];
            break;
        }else{
            _selectBtn.selected = NO;
            [_selectBtn setImage:Pic_btn_UnSelected forState:UIControlStateNormal];
        }
    }
    
    if (selectArray.count <1) {
        _selectBtn.selected = NO;
        [_selectBtn setImage:Pic_btn_UnSelected forState:UIControlStateNormal];
    }
}

-(void)loadPhotoData:(ZZPhoto *)assetItem
{
    img_play.hidden = YES;
    if ([assetItem isKindOfClass:[ZZPhoto class]]) {
        
        [[PHImageManager defaultManager] requestImageForAsset:assetItem.asset targetSize:CGSizeMake(200, 200) contentMode:PHImageContentModeAspectFit options:nil resultHandler:^(UIImage *result, NSDictionary *info){
            self.photo.image = result;
            
        }];
        
    }
}

@end