IVTMeGrabCell.m 5.49 KB
//
//  IVTMeGrabCell.m
//  IVTMeLive
//
//  Created by XRG on 16/4/28.
//  Copyright © 2016年 Joky. All rights reserved.
//

#import "IVTMeGrabCell.h"
#import "Masonry.h"
#import "UIColor+IVTMeColor.h"
#import "UIFont+IVTMeFont.h"

@interface IVTMeGrabCell()
{
    UILabel *name;
    UILabel *mark;
    UILabel *good;
    UIImageView *head;
    UIImageView *sex;
    UIImageView *crow;
}

@end
@implementation IVTMeGrabCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        
        _headIcon = [[UIImageView alloc] init];
        _headIcon.image = [UIImage imageNamed:@"红包手气-头像2"];
        _headIcon.layer.cornerRadius = _headIcon.bounds.size.width/2;
        _headIcon.layer.masksToBounds = YES;
        _headIcon.contentMode = UIViewContentModeScaleAspectFill;
        [self.contentView addSubview:_headIcon];
        __unsafe_unretained typeof (self) wself = self;
        
        [_headIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(wself.contentView.mas_leading).with.offset(12);
            make.centerY.equalTo(wself.contentView);
            make.size.mas_equalTo(CGSizeMake(25, 25));
            
        }];
        
        
        _name = [[UILabel alloc]init];
        [self.contentView addSubview:_name];
        _name.backgroundColor = [UIColor clearColor];
        _name.textColor = [UIColor YXColorWithHexCode:@"#343434"];
        _name.font = [UIFont YXFontOfSize:14];
        _name.text = [[IVTAccountTool getNickName] base64DecodedToString];
        _name.textAlignment = NSTextAlignmentLeft;
        [_name mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(wself.contentView);
            make.left.equalTo(_headIcon.mas_right).with.offset(7);
            make.size.mas_equalTo(CGSizeMake(90, 15));
        }];
        

        
        _gold = [[UIImageView alloc]init];
        _gold.image = [UIImage imageNamed:@"中国币"];
        [self.contentView addSubview:_gold];
        [_gold mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(wself.contentView);
            make.right.equalTo(wself.contentView).with.offset(-12);
            make.size.mas_equalTo(CGSizeMake(13, 13));
            
        }];
        

        
        
        _mark = [[UILabel alloc]init];
        [self.contentView addSubview:_mark];
        _mark.backgroundColor = [UIColor clearColor];
        _mark.textColor = [UIColor YXColorWithHexCode:@"#8A0000"];
        _mark.font = [UIFont YXFontOfSize:10];
        _mark.text = @"20";
        _mark.textAlignment = NSTextAlignmentCenter;
        [_mark mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(wself.contentView);
            make.right.equalTo(_gold.mas_left).with.offset(-6);
            make.size.mas_equalTo(CGSizeMake(30, 12));
        }];
        
        _sex = [[UIImageView alloc]init];
        _sex.image = [UIImage imageNamed:@"性别女"];
        [self.contentView addSubview:_sex];
        [_sex sizeToFit];
        [_sex mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(wself.contentView);
            make.right.equalTo(_mark.mas_left).with.offset(-10);
            make.size.mas_equalTo(CGSizeMake(11.5, 14));
        }];
        
        _lineView =[[UIView alloc]init];
        [self.contentView addSubview:_lineView];
        _lineView.backgroundColor = [UIColor IVTSeparatorColor];
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(wself.contentView.mas_top).with.offset(35);
            make.height.mas_equalTo(@(0.5));
            make.leading.equalTo(wself.contentView.mas_leading);
            make.trailing.equalTo(wself.contentView.mas_trailing);
            
        }];
        
    }
    return self;
}

- (void)setCellModel:(IVTGetRedPackedModel *)cellModel
{
    __unsafe_unretained typeof (self) wself = self;
    //  姓名
    _name.text = cellModel.name;

    
    //  头像
    [_headIcon sd_setImageWithURL:[NSURL URLWithString:cellModel.avatar] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//        self.headIcon.alpha = 0.0;
//        [UIView transitionWithView:self.headIcon
//                          duration:1.0
//                           options:UIViewAnimationOptionTransitionCrossDissolve
//                        animations:^{
//                            [self.headIcon setImage:image];
//                            self.headIcon.alpha = 1.0;
//                        } completion:NULL];
    }];
    
    //  性别
    if ([cellModel.sex isEqualToString:@"male"]) {
        [_sex setImage:[UIImage imageNamed:@"性别男"]];
    }else if ([cellModel.sex isEqualToString:@"female"]){
        [_sex setImage:[UIImage imageNamed:@"性别女"]];
    } else {
        [_sex setImage:[UIImage imageNamed:@"性别女"]];
    }
    [_sex mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(wself.contentView);
        make.left.equalTo(_name.mas_right).with.offset(4);
        make.size.mas_equalTo(CGSizeMake(11.5, 14));
    }];
    //  金币
    _mark.text = [NSString stringWithFormat:@"%@",cellModel.money];
    
    //  用户ID
    _userId = cellModel.userId;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end