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

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

@interface IVTMeUnGrabView()
{
    UIView *_infoBgView;
    UILabel *_nick;
    UIImageView *_sex;
    UIImageView *_grade;
    UILabel *_lelveNum;
    
    UIImageView *top;
}

@property(nonatomic,strong)UIView *shadowView;
@end


@implementation IVTMeUnGrabView




-(void)willMoveToSuperview:(UIView *)newSuperview
{
    [super willMoveToSuperview:newSuperview];
    
    if(newSuperview == nil)
    {
        [[self subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
        
        return ;
    }
}


-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        UIView *shadowView = [[UIView alloc]init];
        shadowView.frame = [UIScreen mainScreen].bounds;
        shadowView.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.8];
        self.shadowView = shadowView;
        [self addSubview:shadowView];
        
        CGFloat heightForPacket = (kScreenHeight - 340)/2;
        //上半部分
        top = [[UIImageView alloc]init];
        top.image = [UIImage imageNamed:@"拆红包上滑后-红包打开"];
        top.userInteractionEnabled = YES;
        [self.shadowView addSubview:top];
        [top mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_shadowView.mas_top).with.offset(heightForPacket);
            make.centerX.equalTo(_shadowView);
            
            
        }];
        //中间
        UIImageView *middle = [[UIImageView alloc]init];
        middle.image = [UIImage imageNamed:@"未抢到红包-白色底"];
        middle.userInteractionEnabled = YES;
        [self.shadowView addSubview:middle];
        [middle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(top.mas_bottom).with.offset(-25);
            make.centerX.equalTo(_shadowView);
            
            
        }];
        //下半部分
//        UIImageView *bottom = [[UIImageView alloc]init];
//        bottom.image = [UIImage imageNamed:@"红包-关闭按钮底条"];
//        [self.shadowView addSubview:bottom];
//        bottom.userInteractionEnabled  = YES;
//        [bottom mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(middle.mas_bottom);
//            make.centerX.equalTo(_shadowView);
//            make.size.mas_equalTo(CGSizeMake(270, 35));
//            
//        }];
        
        
        
        UIButton *close  =[UIButton buttonWithType:UIButtonTypeCustom];
        [close setBackgroundImage:[UIImage imageNamed:@"抢红包-关闭按钮"] forState:UIControlStateNormal];
        close.enabled = YES;
        [_shadowView addSubview:close];
        [close mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(middle.mas_bottom).with.offset(-1);
            make.centerX.equalTo(_shadowView);
            make.size.mas_equalTo(CGSizeMake(270, 35));
            
        }];

        [close addTarget:self action:@selector(closeClick:) forControlEvents:UIControlEventTouchUpInside];
        
        
        //头像
        _headIcon = [[UIImageView alloc]init];
        _headIcon.image = [UIImage imageNamed:@"抢红包头像"];
        _headIcon.layer.masksToBounds = YES; //没这句话它圆不起来
        _headIcon.layer.cornerRadius = 35.0; //设置图片圆角的尺度
        [middle addSubview:_headIcon];
        [_headIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(top.mas_top).with.offset(31);
            make.centerX.equalTo(top.mas_centerX);
            make.size.mas_equalTo(CGSizeMake(70, 70));
        }];


        _infoBgView = [[UIView alloc] init];
        [middle addSubview:_infoBgView];
        [_infoBgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_headIcon.mas_bottom).with.offset(12);
            make.centerX.equalTo(middle);
        }];
        
        //昵称
        _nick = [[UILabel alloc]init];
        [_infoBgView addSubview:_nick];
        _nick.textColor = [UIColor YXColorWithHexCode:@"5B5B5B"];
        _nick.font = [UIFont YXFontOfSize:13];
        [_nick mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_infoBgView.mas_top).with.offset(4);
            make.bottom.equalTo(_infoBgView.mas_bottom).with.offset(-4);
            make.left.equalTo(_infoBgView.mas_left);
        }];
        
        _sex = [[UIImageView alloc]init];
        [_infoBgView addSubview:_sex];
        [_sex mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_nick);
            make.left.equalTo(_nick.mas_right).with.offset(5);
            make.size.mas_equalTo(CGSizeMake(12, 14));
        }];
        
        _grade = [[UIImageView alloc]init];
        _grade.image = [IVTAccountTool showLevel:[IVTAccountTool getLevel]].image;
        [_infoBgView addSubview:_grade];
        _grade.userInteractionEnabled =YES;
        [_grade mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_nick);
            make.left.equalTo(_sex.mas_right).with.offset(5);
            make.size.mas_equalTo(CGSizeMake(29, 14));
            make.right.equalTo(_infoBgView.mas_right);
        }];
        
        _lelveNum  =[[UILabel alloc]init];
        _lelveNum.textColor = [UIColor whiteColor];
        _lelveNum.font = [UIFont YXFontOfSize:10];
        [_grade addSubview:_lelveNum];
        [_lelveNum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_grade.mas_top).with.offset(0);
            make.right.equalTo(_grade.mas_right).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(14, 14));
        }];

        //手太慢,抢光了
        _tips = [[UILabel alloc]init];
        [middle addSubview:_tips];
        
        _tips.textColor = [UIColor YXColorWithHexCode:@"DBCAB2"];
        _tips.font = [UIFont boldSystemFontOfSize:15];
        [_tips mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_nick.mas_bottom).with.offset(40);
            make.centerX.equalTo(middle);
        }];
        
        UILabel *shouqi = [[UILabel alloc]init];
        [middle addSubview:shouqi];
        shouqi.text  =@"看看大家的手气";
        shouqi.textColor = [UIColor YXColorWithHexCode:@"5B5B5B"];
        shouqi.font = [UIFont YXFontOfSize:13];
        [shouqi mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_tips.mas_bottom).with.offset(40);
            make.centerX.equalTo(middle);
        }];
        
        
        UIButton *arrow  =[UIButton buttonWithType:UIButtonTypeCustom];
        [arrow setImage:[UIImage imageNamed:@"未抢到红包-查看大家手气按钮"] forState:UIControlStateNormal];
        [shadowView addSubview:arrow];
        arrow.enabled = YES;
        [arrow mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(shouqi.mas_bottom).with.offset(14);
            make.centerX.equalTo(middle);
            make.size.mas_equalTo(CGSizeMake(30, 30));
            
        }];

        
        UIButton *goDetailButton  =[UIButton buttonWithType:UIButtonTypeCustom];

        [shadowView addSubview:goDetailButton];
        goDetailButton.enabled = YES;
        [goDetailButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(shouqi.mas_top).with.offset(0);
            make.left.equalTo(shouqi.mas_left);
            make.right.equalTo(shouqi.mas_right);
            make.bottom.equalTo(arrow.mas_bottom);
        }];
        [goDetailButton addTarget:self action:@selector(arrowClick:) forControlEvents:UIControlEventTouchUpInside];

    }
    
    return self;
}

- (void)setLevelString:(NSString *)levelString{
    _levelString = levelString;
    _lelveNum.text = [NSString stringWithFormat:@"%@",levelString];
}
- (void)setSexString:(NSString *)sexString{
    _sexString = sexString;
    if ([sexString isEqualToString:@"male"]) {
        [_sex setImage:[UIImage imageNamed:@"性别男"]];
    }else if ([sexString isEqualToString:@"female"]){
        [_sex setImage:[UIImage imageNamed:@"性别女"]];
    } else {
        [_sex setImage:[UIImage imageNamed:@"性别女"]];
    }
}
- (void)setNameString:(NSString *)nameString{
    _nameString = [nameString base64DecodedToString];

    _nick.text  = nameString;
}

-(void)arrowClick:(UIButton *)button{
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(showPacketList)]) {
        
        [self.delegate showPacketList];
    }
}

-(void)closeClick:(UIButton *)button{
    if (self.delegate && [self.delegate respondsToSelector:@selector(closeClick)]) {
        [self.delegate respondsToSelector:@selector(closeClick)];
    }
    [self.shadowView removeFromSuperview];
    [self removeFromSuperview];
}

@end