123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- //
- // KDPSupplyGoodCollectionViewCell.m
- // KuDianProject
- //
- // Created by admin on 2019/7/4.
- // Copyright © 2019 KDP. All rights reserved.
- //
- #import "KDPSupplyGoodCollectionViewCell.h"
- @interface KDPSupplyGoodCollectionViewCell()
- @property (nonatomic, strong) UIImageView *iconImageView;
- @property (nonatomic, strong) UILabel *goodLabel;
- @property (nonatomic, strong) UILabel *priceLabel;
- @property (nonatomic, strong) UILabel *disCountPriceLabel;
- @property (nonatomic, strong) UIImageView *quanImageView;
- @property (nonatomic, strong) UILabel *quanLabel;
- @property (nonatomic, strong) UIView *contenAView;
- @property (nonatomic, strong) UILabel *profitLabel;
- @end
- @implementation KDPSupplyGoodCollectionViewCell
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- [self setUpSubViews];
- [self setSubViewsConstraints];
- }
- return self;
- }
- - (void)setUpSubViews{
- self.contentView.backgroundColor = [UIColor whiteColor];
-
- self.iconImageView = [[UIImageView alloc] init];
- [self.contentView addSubview:self.iconImageView];
-
- self.goodLabel = [[UILabel alloc] init];
- self.goodLabel.font = FONT_SYS(15);
- self.goodLabel.textColor = [UIColor colorWithHex:0x333333];
- self.goodLabel.numberOfLines = 1;
- [self.goodLabel sizeToFit];
- self.goodLabel.textAlignment = NSTextAlignmentLeft;
- [self.contentView addSubview:self.goodLabel];
-
- self.priceLabel = [[UILabel alloc] init];
- [self.contentView addSubview:self.priceLabel];
-
- self.disCountPriceLabel = [[UILabel alloc] init];
- [self.contentView addSubview:self.disCountPriceLabel];
-
- [self.contentView addSubview:self.quanImageView];
-
- self.quanLabel = [[UILabel alloc] init];
- self.quanLabel.textColor = [UIColor baseColor];
- self.quanLabel.font = FONT_SYS(12);
- self.quanLabel.textAlignment = NSTextAlignmentCenter;
- [self.quanImageView addSubview:self.quanLabel];
-
- self.contenAView = [[UIView alloc] init];
- self.contenAView.layer.cornerRadius = 6;
- self.contenAView.layer.masksToBounds = YES;
- [self.contentView bringSubviewToFront:self.contenAView];
- [self.contentView addSubview:self.contenAView];
- UILabel *profit = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 39, 26)];
- profit.textColor = [UIColor whiteColor];
- profit.font = FONT_SYS(12);
- profit.textAlignment = NSTextAlignmentCenter;
- profit.text = @"利润";
- [self.contenAView addSubview:profit];
-
- [self.contenAView setGradientBackgroundWithColors:@[[UIColor colorWithHex:0xFF235F],[UIColor colorWithHex:0xFF7676]] locations:@[@0,@1] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
- self.profitLabel = [[UILabel alloc] init];
- self.profitLabel.textColor = [UIColor whiteColor];
- self.profitLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size: 16];
- self.profitLabel.textAlignment = NSTextAlignmentCenter;
- [self.contenAView addSubview:self.profitLabel];
- }
- - (void)setSubViewsConstraints{
- [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.equalTo(self.contentView);
- make.height.equalTo(173);
- }];
- [self.goodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView.mas_left).offset(10);
- make.right.equalTo(self.contentView.mas_right).offset(-6);
- make.top.equalTo(self.iconImageView.mas_bottom).offset(11);
- make.height.equalTo(21);
- }];
- [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView.mas_left).offset(10);
- make.top.equalTo(self.goodLabel.mas_bottom).offset(7);
- }];
- [self.disCountPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.priceLabel.mas_right).offset(2);
- make.centerY.equalTo(self.priceLabel);
- }];
- [self.quanImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.priceLabel);
- make.right.equalTo(self.contentView.mas_right).offset(-6);
- make.size.equalTo(CGSizeMake(50, 16));
- }];
- [self.quanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.top.bottom.equalTo(self.quanImageView);
- make.width.equalTo(40);
- }];
- [self.contenAView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView.mas_left).offset(10);
- make.top.equalTo(self.priceLabel.mas_bottom).offset(7);
- make.size.equalTo(CGSizeMake(78, 26));
- }];
- [self.profitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.top.bottom.equalTo(self.contenAView);
- make.width.equalTo(39);
- }];
- }
- - (void)configCellWithModel:(id)model indexPath:(NSIndexPath *)indexpath{
- KDPGoodsModel *goodModel = (KDPGoodsModel *)model;
- [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:goodModel.img]placeholderImage:[UIImage imageNamed:placholderImg]];
- self.goodLabel.text = goodModel.title;
- NSString *priceString = [NSString stringWithFormat:@"¥%@",goodModel.discount_price];
- NSMutableAttributedString *mutableAttPrice = [[NSMutableAttributedString alloc] initWithString:priceString attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Medium" size: 18]}];
- [mutableAttPrice addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size: 12]} range:[priceString rangeOfString:@"¥"]];
- self.priceLabel.attributedText = mutableAttPrice;
-
- NSString *disCountPrice = [NSString stringWithFormat:@"¥%@",goodModel.price];
- NSAttributedString *disCounrAtt = [[NSAttributedString alloc] initWithString:disCountPrice attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x999999],NSFontAttributeName:FONT_SYS(12),NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle)}];
- self.disCountPriceLabel.attributedText = disCounrAtt;
-
- self.quanLabel.text = goodModel.coupon_price;
-
- if ([goodModel.coupon_price integerValue] == 0) {
- self.quanImageView.hidden = YES;
- } else{
- self.quanImageView.hidden = NO;
- }
- self.profitLabel.text = goodModel.commission_rate;
-
- }
- - (void)layoutSubviews{
- [super layoutSubviews];
- }
- - (UIImageView *)quanImageView{
- if (!_quanImageView) {
- _quanImageView = [[UIImageView alloc] init];
- _quanImageView.image = [UIImage imageNamed:@"coupon_icon"];
- UILabel *quanLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 16)];
- quanLabel.textColor = [UIColor whiteColor];
- quanLabel.font = FONT_SYS(12);
- quanLabel.text = @"券";
- quanLabel.textAlignment = NSTextAlignmentCenter;
- [_quanImageView addSubview:quanLabel];
- }
- return _quanImageView;
- }
- @end
|