// // KBMineRecomGoodsView.m // YouHuiProject // // Created by 小花 on 2018/11/7. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBMineRecomGoodsView.h" @interface KBMineRecomGoodsView () { UILabel *_titleLb; } @property (nonatomic, strong) UIImageView *icon; @property (nonatomic, strong) UILabel *title; @property (nonatomic, strong) YYLabel *couple_price; @property (nonatomic, strong) YYLabel *price; @property (nonatomic, strong) UIImageView *quanBg; @property (nonatomic, strong) UILabel *quanType; @property (nonatomic, strong) UILabel *quanNum; @property (nonatomic, strong) UIView *alphaView; @end @implementation KBMineRecomGoodsView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.layer.cornerRadius = 6; self.backgroundColor = [UIColor whiteColor]; [self initSubViews]; } return self; } - (void)initSubViews { UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 8, 24, 24)]; imgView.image = [UIImage imageNamed:@"mine_re"]; [self addSubview:imgView]; UILabel *titleLb = [[UILabel alloc] initWithFrame:CGRectMake(imgView.right+5, 0, 200, Fitsize(36))]; titleLb.font = [UIFont systemFontOfSize:Fitsize(14)]; titleLb.textColor = [UIColor YHColorWithHex:0x000000]; _titleLb = titleLb; titleLb.centerY = imgView.centerY; [self addSubview:titleLb]; UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-40-10-10, 0, 40, 40)]; [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside]; rightBtn.centerY = titleLb.centerY; [rightBtn setImage:[UIImage imageNamed:@"more_acc"] forState:UIControlStateNormal]; UILabel *Line = [[UILabel alloc] initWithFrame:CGRectMake(5, titleLb.bottom, self.width-10, 1)]; Line.backgroundColor = [UIColor yhGrayColor]; [self addSubview:Line]; [self addSubview:self.icon]; [self addSubview:self.title]; [self addSubview:self.couple_price]; [self addSubview:self.price]; [self addSubview:self.quanBg]; [self.quanBg addSubview:self.quanType]; [self.quanBg addSubview:self.quanNum]; [self addSubview:self.alphaView]; [self addSubview:rightBtn]; [self.icon mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(5); make.top.mas_equalTo(Line.mas_bottom).mas_offset(12); make.width.height.mas_equalTo(70); }]; [self.title mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.icon.mas_right).mas_offset(10); make.top.mas_equalTo(self.icon.mas_top); make.right.mas_equalTo(-10); }]; [self.couple_price mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.title); make.bottom.mas_equalTo(self.icon.mas_bottom).mas_offset(-3); }]; [self.price mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.couple_price.mas_right).mas_offset(15); make.centerY.mas_equalTo(self.couple_price); }]; [self.quanBg mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(67); make.height.mas_equalTo(22); make.bottom.mas_equalTo(self.icon.mas_bottom).mas_offset(-5); make.right.mas_equalTo(-10); }]; [self.quanType mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.left.mas_equalTo(0); make.width.mas_equalTo(24); }]; [self.quanNum mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(27); make.top.bottom.mas_equalTo(0); make.right.mas_equalTo(-3); }]; [self.alphaView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(UIEdgeInsetsZero); }]; } - (void)setModel:(KBChildGoodModel *)model { _model = model; _titleLb.text = model.tag_disc; [self.icon sd_setImageWithURL:[NSURL URLWithString:model.img]]; self.title.text = model.title; NSString *discount_price = [NSString stringWithFormat:@"券后¥%.2f",[model.discount_price floatValue]]; NSMutableAttributedString *disAttr = [[NSMutableAttributedString alloc] initWithString:discount_price]; [disAttr yy_setFont:[UIFont systemFontOfSize:12] range:NSMakeRange(0, 3)]; [disAttr yy_setFont:[UIFont systemFontOfSize:16] range:NSMakeRange(3, discount_price.length-3)]; disAttr.yy_color = [UIColor homeRedColor]; self.couple_price.attributedText = disAttr; NSString *price = [NSString stringWithFormat:@"¥%.2f",[model.price floatValue]]; NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:price]; attrStr.yy_font = [UIFont systemFontOfSize:11]; attrStr.yy_color = [UIColor YHColorWithHex:0x999999]; YYTextDecoration *decoration = [YYTextDecoration decorationWithStyle:YYTextLineStyleSingle width:@1 color:[UIColor YHColorWithHex:0x999999]]; [attrStr yy_setTextStrikethrough:decoration range:NSMakeRange(0, price.length)]; self.price.attributedText = attrStr; self.quanNum.text = [NSString stringWithFormat:@"%@元",model.coupon_price]; self.quanBg.hidden = ![model.is_coupon boolValue]; } - (void)tapAlphaView { if (self.tapBlock) { self.tapBlock(_model); } } - (void)rightBtnClick { if (self.rightClick) { self.rightClick(); } } - (UIImageView *)icon { if (!_icon) { _icon = [[UIImageView alloc] init]; _icon.layer.cornerRadius = 4; _icon.backgroundColor = [UIColor yhGrayColor]; } return _icon; } - (UILabel *)title { if (!_title) { _title = [[UILabel alloc] init]; _title.numberOfLines = 2; _title.font = [UIFont systemFontOfSize:14]; } return _title; } - (YYLabel *)couple_price { if (!_couple_price) { _couple_price = [[YYLabel alloc] init]; _couple_price.textColor = [UIColor homeRedColor]; _couple_price.font = [UIFont systemFontOfSize:16]; _couple_price.displaysAsynchronously = YES; } return _couple_price; } - (YYLabel *)price { if (!_price) { _price = [[YYLabel alloc] init]; _price.textColor = [UIColor YHColorWithHex:0xA2A0A0]; _price.font = [UIFont systemFontOfSize:12]; } return _price; } - (UIImageView *)quanBg { if (!_quanBg) { _quanBg = [[UIImageView alloc] init]; _quanBg.image = [UIImage imageNamed:@"quan_bg_3"]; } return _quanBg; } - (UILabel *)quanType { if (!_quanType) { _quanType = [[UILabel alloc] init]; _quanType.text = @"券"; _quanType.textColor = [UIColor whiteColor]; _quanType.font = [UIFont systemFontOfSize:13]; _quanType.textAlignment = NSTextAlignmentCenter; } return _quanType; } - (UILabel *)quanNum { if (!_quanNum) { _quanNum = [[UILabel alloc] init]; _quanNum.textColor = [UIColor whiteColor]; _quanNum.font = [UIFont systemFontOfSize:13]; _quanNum.textAlignment = NSTextAlignmentCenter; _quanNum.adjustsFontSizeToFitWidth = YES; } return _quanNum; } - (UIView *)alphaView { if (!_alphaView) { _alphaView = [[UIView alloc] init]; _alphaView.backgroundColor = [UIColor clearColor]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAlphaView)]; [_alphaView addGestureRecognizer:tap]; } return _alphaView; } @end