IVTMeGiftCell.m 3.84 KB
//
//  IVTMeGiftCell.m
//  IVTMeLive
//
//  Created by XRG on 16/6/6.
//  Copyright © 2016年 Joky. All rights reserved.
//

#import "IVTMeGiftCell.h"

@interface IVTMeGiftCell ()
{
    UIImageView *_gift;
    UIButton *_lianFa;
    UILabel *_money;
    UIImageView *_chineseCoin;
    UILabel *_jingyan;
}
@end

@implementation IVTMeGiftCell

-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self prepareUI];
    }
    return self;
}


-(void)prepareUI{
    __unsafe_unretained typeof (self) wself = self;
    _gift = [[UIImageView alloc]init];
    [self.contentView addSubview:_gift];
    [_gift mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(wself.contentView.mas_top).with.offset(10);
        make.left.equalTo(wself.contentView.mas_left).with.offset(10);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    

    _lianFa = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:_lianFa];
    [_lianFa mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(wself.contentView.mas_top).with.offset(5);
        make.left.equalTo(_gift.mas_right).with.offset(10);
        make.size.mas_equalTo(CGSizeMake(10, 10));
        
    }];
    

    _money = [[UILabel alloc]init];
    _money.textColor = [UIColor IVTLightRedColor];
    _money.font = [UIFont YXFontOfSize:11];
    [self.contentView addSubview:_money];
    [_money mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_gift.mas_bottom).with.offset(10);
        make.centerX.equalTo(wself.contentView).with.offset(10);
        make.size.mas_equalTo(CGSizeMake(30, 15));
        
    }];

    
    _chineseCoin = [[UIImageView alloc]init];
    _chineseCoin.image = [UIImage imageNamed:@"小中国币(礼物下面)"];
    [self.contentView addSubview:_chineseCoin];
    [_chineseCoin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_gift.mas_bottom).with.offset(10);
        make.right.equalTo(_money.mas_left).with.offset(-3);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    
    
    _jingyan = [[UILabel alloc]init];
    _jingyan.textColor = [UIColor YXColorWithHexCode:@"787878"];
    _jingyan.font = [UIFont YXFontOfSize:10];
    _jingyan.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:_jingyan];
    [_jingyan mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_gift.mas_centerX);
        make.top.equalTo(_chineseCoin.mas_bottom).with.offset(5);
        make.size.mas_equalTo(CGSizeMake(60, 15));
     }];

}

- (void)setEntity:(NSDictionary *)entity{
    _entity = entity;
    NSLog(@"----%@",self.entity[@"icon"]);

    NSString *imageUrlString = [[NSString stringWithFormat:@"%@",self.entity[@"icon"]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    [_gift sd_setImageWithURL:[NSURL URLWithString:imageUrlString] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    }];
    
    if ([self.entity[@"type"] integerValue] == 0) {
        [_lianFa setImage:[UIImage imageNamed:@"连发"] forState:UIControlStateNormal];
        [_lianFa setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
        _lianFa.hidden = NO;
        if ([self.entity[@"isSelected"] integerValue]) {
            _lianFa.selected = YES;
        }
        else{
            _lianFa.selected = NO;
        }
    }
    else{
        [_lianFa setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateNormal];
        if ([self.entity[@"isSelected"] integerValue]) {
            _lianFa.hidden = NO;
        }
        else{
            _lianFa.hidden = YES;
        }
    }
    
    _money.text = [NSString stringWithFormat:@"%@",self.entity[@"price"]];

    _jingyan.text = [NSString stringWithFormat:@"经验:%@",self.entity[@"exp"]];
    

}





@end