// // KBBuyLimitHeader.m // YouHuiProject // // Created by 小花 on 2018/7/9. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBBuyLimitHeader.h" #import "KBBuyLimitGoodView.h" @interface KBBuyLimitHeader (){ UILabel *_title; } @property (nonatomic, strong) KBBuyLimitGoodView *limitGoodView; @end @implementation KBBuyLimitHeader - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubView]; } return self; } - (void)initSubView { UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, 116)]; bgView.backgroundColor = [UIColor YHColorWithHex:0x3F3D39]; [self addSubview:bgView]; UIView *cardView = [[UIView alloc] initWithFrame:CGRectMake(15, 0, self.width-30, 156)]; cardView.backgroundColor = [UIColor whiteColor]; cardView.layer.cornerRadius = 8; cardView.layer.shadowColor = [UIColor blackColor].CGColor; cardView.layer.shadowOffset = CGSizeMake(2, 5); cardView.layer.shadowOpacity = 0.3; cardView.layer.shadowRadius = 3; [self addSubview:cardView]; UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(10, 13, 16, 16)]; icon.image = [UIImage imageNamed:@"willKong"]; [cardView addSubview:icon]; UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(icon.right+3, 5, 200, 33)]; title.text = @"即将售空"; title.textColor = [UIColor YHColorWithHex:0xFF5000]; title.font = [UIFont systemFontOfSize:14]; [cardView addSubview:title]; _title = title; self.limitGoodView = [[KBBuyLimitGoodView alloc] initWithFrame:CGRectMake(10, 42, cardView.width-20, 94)]; [cardView addSubview:self.limitGoodView]; UIView *gesView = [[UIView alloc] initWithFrame:self.bounds]; gesView.backgroundColor = [UIColor clearColor]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)]; gesView.backgroundColor = [UIColor clearColor]; [gesView addGestureRecognizer:tap]; [self addSubview:gesView]; } - (void)tapAction { if (!self.canBuy) { [MBProgressHUD showMessage:@"抢购还未开始"]; return; } if (self.ClickBlock && _model) { self.ClickBlock(_model); } } - (void)setModel:(KBBuyLimitGoodModel *)model { _model = model; [self.limitGoodView setModel:model]; } - (void)setCanBuy:(BOOL)canBuy { _canBuy = canBuy; NSString *title = canBuy?@"即将售空":@"热门关注"; _title.text = title; self.limitGoodView.buyButton.enabled = canBuy; UIColor *color = canBuy?[UIColor homeRedColor]:[UIColor lightGrayColor]; self.limitGoodView.buyButton.backgroundColor = color; } @end