123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- //
- // KBBuyLimitGoodView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/7/9.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBBuyLimitGoodView.h"
- #import "BuyProgressView.h"
- @interface KBBuyLimitGoodView ()
- @property (nonatomic, strong) UIImageView *iconView;
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) BuyProgressView *progressView;
- @property (nonatomic, strong) UILabel *priceLabel;
- @property (nonatomic, strong) UILabel *disPriceLabel;
- @property (nonatomic, strong) UILabel *coupleLabel;
- @end
- @implementation KBBuyLimitGoodView
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- [self initSubViews];
- }
- return self;
- }
- - (void)initSubViews {
- [self addSubview:self.iconView];
- [self addSubview:self.titleLabel];
- [self addSubview:self.priceLabel];
- [self addSubview:self.disPriceLabel];
- [self addSubview:self.buyButton];
- [self addSubview:self.progressView];
- [self addSubview:self.coupleLabel];
-
- [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.mas_equalTo(0);
- make.width.height.mas_equalTo(94);
- }];
-
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(5);
- make.left.mas_equalTo(self.iconView.mas_right).mas_offset(5);
- }];
-
- [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.titleLabel.mas_left);
- make.centerY.mas_equalTo(self.iconView.mas_centerY);
- make.width.mas_equalTo(Fitsize(104));
- make.height.mas_equalTo(Fitsize(14));
- }];
-
- [self.disPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.titleLabel.mas_left);
- make.bottom.mas_equalTo(self.iconView.mas_bottom).mas_offset(-3);
- }];
-
- [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.disPriceLabel.mas_right).mas_offset(7);
- make.centerY.mas_equalTo(self.disPriceLabel.mas_centerY);
- }];
-
- [self.buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(0);
- make.bottom.mas_equalTo(self.priceLabel.mas_bottom);
- make.width.mas_equalTo(Fitsize(77));
- make.height.mas_equalTo(Fitsize(22));
- }];
-
- [self.coupleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(-10);
- make.centerY.mas_equalTo(self.mas_centerY);
- make.height.mas_equalTo(Fitsize(16));
- make.width.mas_equalTo(Fitsize(50));
- }];
-
-
- }
- - (void)setModel:(KBBuyLimitGoodModel *)model {
- _model = model;
- self.titleLabel.text = model.title;
- // [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:Placehold_Img];
- [self.iconView sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil];
- [self.progressView setProgress:model.sale_rate.floatValue/100];
- [self.progressView setCount:model.sale_num];
- self.disPriceLabel.text = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
-
- NSString *price=[NSString stringWithFormat:@"¥%.2f",[model.price floatValue]];
- NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:price];
- [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, price.length)];
- [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor YHColorWithHex:0x999999] range:NSMakeRange(0, price.length)];
- self.priceLabel.attributedText = attri;
- // if (model.commission_price.length > 0) {
- // [self.buyButton setTitle:[NSString stringWithFormat:@"抢赚¥%.2f",[model.commission_price floatValue]] forState:UIControlStateNormal];
- // }else {
- // [self.buyButton setTitle:@"抢购" forState:UIControlStateNormal];
- // }
-
- self.coupleLabel.hidden = ![model.is_coupon boolValue];
- self.coupleLabel.text = [NSString stringWithFormat:@"%@元券",model.coupon_price];
- }
- - (UIImageView *)iconView {
- if (!_iconView) {
- _iconView = [[UIImageView alloc] init];
- _iconView.clipsToBounds = YES;
- _iconView.layer.cornerRadius = 4;
- _iconView.backgroundColor = [UIColor yhGrayColor];
- }
- return _iconView;
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [[UILabel alloc] init];
- _titleLabel.numberOfLines = 2;
- _titleLabel.font = [UIFont systemFontOfSize:Fitsize(14)];
- _titleLabel.textColor = [UIColor YHColorWithHex:0x2D2D2D];
- _titleLabel.text = @"标题加载中...";
- }
- return _titleLabel;
- }
- - (UILabel *)priceLabel {
- if (!_priceLabel) {
- _priceLabel = [[UILabel alloc] init];
- _priceLabel.font = [UIFont systemFontOfSize:Fitsize(12)];
- _priceLabel.textColor = [UIColor YHColorWithHex:0xB6B6B6];
- _priceLabel.text = @"¥--";
- }
- return _priceLabel;
- }
- - (UILabel *)disPriceLabel {
- if (!_disPriceLabel) {
- _disPriceLabel = [[UILabel alloc] init];
- _disPriceLabel.textColor = [UIColor homeRedColor];
- _disPriceLabel.font = [UIFont systemFontOfSize:Fitsize(16)];
- _disPriceLabel.text = @"¥--";
- }
- return _disPriceLabel;
- }
- - (UIButton *)buyButton {
- if (!_buyButton) {
- _buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _buyButton.backgroundColor = [UIColor homeRedColor];
- _buyButton.titleLabel.font = [UIFont systemFontOfSize:13];
- _buyButton.layer.cornerRadius = Fitsize(10);
- _buyButton.titleLabel.textColor = [UIColor whiteColor];
- [_buyButton setTitle:@"抢购" forState:UIControlStateNormal];
- _buyButton.userInteractionEnabled = NO;
- }
- return _buyButton;
- }
- - (BuyProgressView *)progressView {
- if (!_progressView) {
- _progressView = [BuyProgressView new];
- }
- return _progressView;
- }
- - (UILabel *)coupleLabel {
- if (!_coupleLabel) {
- _coupleLabel = [[UILabel alloc] init];
- _coupleLabel.textColor = [UIColor homeRedColor];
- _coupleLabel.font = [UIFont systemFontOfSize:Fitsize(12)];
- _coupleLabel.textAlignment = NSTextAlignmentCenter;
- _coupleLabel.layer.cornerRadius = Fitsize(4);
- _coupleLabel.layer.borderWidth = 1;
- _coupleLabel.layer.borderColor = [UIColor homeRedColor].CGColor;
- _coupleLabel.hidden = YES;
- }
- return _coupleLabel;
- }
- @end
|