| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 | ////  ASProductItemView.m//  Asteria////  Created by iOS on 2023/5/17.//#import "ASProductItemView.h"@interface ASProductItemView ()@property (nonatomic, strong) UIImageView *imgV;@end@implementation ASProductItemView- (void)setModel:(ASProductBaseModel *)model {    _model = model;    [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"product_defualtImg"]];    self.titleLb.text = model.title;    self.hotLb.text = [NSString stringWithFormat:@"SOLD %@", model.sale_num];        self.nowPriceLb.text = model.nowPrice;    if ([model.oldPrice isEqualToString:@""] || [model.oldPrice isEqualToString:model.nowPrice]) {        [self.oldPriceLb setHidden:true];    } else {        [self.oldPriceLb setHidden:false];        NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",model.oldPrice]];        [attStr addAttributes:@{            NSFontAttributeName:[UIFont fontWithName:Rob_Regular size:12],            NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle),            NSStrikethroughColorAttributeName:Col_999,            NSForegroundColorAttributeName:Col_999,        } range:NSMakeRange(0, attStr.length)];                self.oldPriceLb.attributedText = attStr;    }    }- (instancetype)initWithFrame:(CGRect)frame {    self = [super initWithFrame:frame];    if (self) {        [self configSubV];        self.clipsToBounds = true;    }    return  self;}- (void) configSubV {    self.layer.cornerRadius = 8;    self.layer.masksToBounds = true;    self.backgroundColor = _F5F5F5;        [self addSubview:self.imgV];    [self addSubview:self.titleLb];    [self addSubview:self.hotLb];    [self addSubview: self.nowPriceLb];    [self addSubview: self.oldPriceLb];    [self addSubview:self.addCartBt];        [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {        make.width.equalTo(self);        make.height.equalTo(self.mas_width);        make.top.leading.trailing.equalTo(self);    }];    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {        make.top.equalTo(self.imgV.mas_bottom).offset(10);        make.leading.equalTo(self).offset(10);        make.trailing.equalTo(self).offset(-10);    }];    [self.hotLb mas_makeConstraints:^(MASConstraintMaker *make) {        make.leading.equalTo(self.titleLb);        make.top.equalTo(self.titleLb.mas_bottom).offset(7);        make.trailing.equalTo(self.titleLb);        make.height.equalTo(@14);    }];    [self.nowPriceLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];    [self.nowPriceLb mas_makeConstraints:^(MASConstraintMaker *make) {        make.leading.equalTo(self.titleLb);        make.top.greaterThanOrEqualTo(self.hotLb.mas_bottom).offset(11);        make.height.equalTo(@17);        make.bottom.equalTo(self.mas_bottom).offset(-9);    }];        [self.oldPriceLb mas_makeConstraints:^(MASConstraintMaker *make) {        make.bottom.equalTo(self.nowPriceLb);        make.leading.equalTo(self.nowPriceLb.mas_trailing).offset(4);        make.height.equalTo(@16);    }];    [self.addCartBt mas_makeConstraints:^(MASConstraintMaker *make) {        make.width.height.equalTo(@24);        make.trailing.equalTo(self).offset(-10);        make.bottom.equalTo(self).offset(-10);        make.leading.greaterThanOrEqualTo(self.oldPriceLb.mas_trailing).offset(8);    }];        }- (UIImageView *)imgV {    if (!_imgV) {        UIImageView *v = [[UIImageView alloc] init];        v.contentMode = UIViewContentModeScaleToFill;        _imgV = v;    }    return  _imgV;}- (UILabel *)titleLb {    if (!_titleLb) {        UILabel *lb = [[UILabel alloc] init];        lb.font = [UIFont fontWithName:Rob_Regular size:12];        lb.textColor = [UIColor blackColor];        lb.textAlignment = NSTextAlignmentLeft;        lb.numberOfLines = 2;        _titleLb = lb;    }    return  _titleLb;}- (UILabel *)nowPriceLb {    if (!_nowPriceLb) {        UILabel *lb = [[UILabel alloc] init];        lb.font = [UIFont fontWithName:Rob_Bold size:14];        lb.textColor = [UIColor blackColor];        lb.textAlignment = NSTextAlignmentLeft;        _nowPriceLb = lb;    }    return  _nowPriceLb;}- (UILabel *)oldPriceLb {    if (!_oldPriceLb) {        UILabel *lb = [[UILabel alloc] init];        lb.font = [UIFont fontWithName:Rob_Regular size:12];        lb.textColor = Col_999;        lb.textAlignment = NSTextAlignmentLeft;        _oldPriceLb = lb;    }    return  _oldPriceLb;}- (UILabel *)hotLb {    if (!_hotLb) {        UILabel *lb = [[UILabel alloc] init];        lb.font = [UIFont fontWithName:Rob_Regular size:12];        lb.textColor = Col_666;        lb.textAlignment = NSTextAlignmentLeft;        _hotLb = lb;    }    return  _hotLb;}-(UIButton *)addCartBt {    if (!_addCartBt) {        UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];        [bt setImage:[UIImage imageNamed:@"product_addCart"] forState:UIControlStateNormal];        [bt addTarget:self action:@selector(addCartBtAction) forControlEvents:UIControlEventTouchUpInside];        _addCartBt = bt;    }    return _addCartBt;}- (void)addCartBtAction {    if (self.addCartBlock) {        self.addCartBlock(self.model);    }}@end
 |