酷店

KDPSupplyGoodCollectionViewCell.m 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // KDPSupplyGoodCollectionViewCell.m
  3. // KuDianProject
  4. //
  5. // Created by admin on 2019/7/4.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPSupplyGoodCollectionViewCell.h"
  9. @interface KDPSupplyGoodCollectionViewCell()
  10. @property (nonatomic, strong) UIImageView *iconImageView;
  11. @property (nonatomic, strong) UILabel *goodLabel;
  12. @property (nonatomic, strong) UILabel *priceLabel;
  13. @property (nonatomic, strong) UILabel *disCountPriceLabel;
  14. @property (nonatomic, strong) UIImageView *quanImageView;
  15. @property (nonatomic, strong) UILabel *quanLabel;
  16. @property (nonatomic, strong) UIView *contenAView;
  17. @property (nonatomic, strong) UILabel *profitLabel;
  18. @end
  19. @implementation KDPSupplyGoodCollectionViewCell
  20. - (instancetype)initWithFrame:(CGRect)frame{
  21. if (self = [super initWithFrame:frame]) {
  22. [self setUpSubViews];
  23. [self setSubViewsConstraints];
  24. }
  25. return self;
  26. }
  27. - (void)setUpSubViews{
  28. self.contentView.backgroundColor = [UIColor whiteColor];
  29. self.iconImageView = [[UIImageView alloc] init];
  30. [self.contentView addSubview:self.iconImageView];
  31. self.goodLabel = [[UILabel alloc] init];
  32. self.goodLabel.font = FONT_SYS(15);
  33. self.goodLabel.textColor = [UIColor colorWithHex:0x333333];
  34. self.goodLabel.numberOfLines = 1;
  35. [self.goodLabel sizeToFit];
  36. self.goodLabel.textAlignment = NSTextAlignmentLeft;
  37. [self.contentView addSubview:self.goodLabel];
  38. self.priceLabel = [[UILabel alloc] init];
  39. [self.contentView addSubview:self.priceLabel];
  40. self.disCountPriceLabel = [[UILabel alloc] init];
  41. [self.contentView addSubview:self.disCountPriceLabel];
  42. [self.contentView addSubview:self.quanImageView];
  43. self.quanLabel = [[UILabel alloc] init];
  44. self.quanLabel.textColor = [UIColor baseColor];
  45. self.quanLabel.font = FONT_SYS(12);
  46. self.quanLabel.textAlignment = NSTextAlignmentCenter;
  47. [self.quanImageView addSubview:self.quanLabel];
  48. self.contenAView = [[UIView alloc] init];
  49. self.contenAView.layer.cornerRadius = 6;
  50. self.contenAView.layer.masksToBounds = YES;
  51. [self.contentView bringSubviewToFront:self.contenAView];
  52. [self.contentView addSubview:self.contenAView];
  53. UILabel *profit = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 39, 26)];
  54. profit.textColor = [UIColor whiteColor];
  55. profit.font = FONT_SYS(12);
  56. profit.textAlignment = NSTextAlignmentCenter;
  57. profit.text = @"利润";
  58. [self.contenAView addSubview:profit];
  59. [self.contenAView setGradientBackgroundWithColors:@[[UIColor colorWithHex:0xFF235F],[UIColor colorWithHex:0xFF7676]] locations:@[@0,@1] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
  60. self.profitLabel = [[UILabel alloc] init];
  61. self.profitLabel.textColor = [UIColor whiteColor];
  62. self.profitLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size: 16];
  63. self.profitLabel.textAlignment = NSTextAlignmentCenter;
  64. [self.contenAView addSubview:self.profitLabel];
  65. }
  66. - (void)setSubViewsConstraints{
  67. [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.top.left.right.equalTo(self.contentView);
  69. make.height.equalTo(173);
  70. }];
  71. [self.goodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.left.equalTo(self.contentView.mas_left).offset(10);
  73. make.right.equalTo(self.contentView.mas_right).offset(-6);
  74. make.top.equalTo(self.iconImageView.mas_bottom).offset(11);
  75. make.height.equalTo(21);
  76. }];
  77. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.left.equalTo(self.contentView.mas_left).offset(10);
  79. make.top.equalTo(self.goodLabel.mas_bottom).offset(7);
  80. }];
  81. [self.disCountPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.left.equalTo(self.priceLabel.mas_right).offset(2);
  83. make.centerY.equalTo(self.priceLabel);
  84. }];
  85. [self.quanImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.centerY.equalTo(self.priceLabel);
  87. make.right.equalTo(self.contentView.mas_right).offset(-6);
  88. make.size.equalTo(CGSizeMake(50, 16));
  89. }];
  90. [self.quanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.right.top.bottom.equalTo(self.quanImageView);
  92. make.width.equalTo(40);
  93. }];
  94. [self.contenAView mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.left.equalTo(self.contentView.mas_left).offset(10);
  96. make.top.equalTo(self.priceLabel.mas_bottom).offset(7);
  97. make.size.equalTo(CGSizeMake(78, 26));
  98. }];
  99. [self.profitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  100. make.right.top.bottom.equalTo(self.contenAView);
  101. make.width.equalTo(39);
  102. }];
  103. }
  104. - (void)configCellWithModel:(id)model indexPath:(NSIndexPath *)indexpath{
  105. KDPGoodsModel *goodModel = (KDPGoodsModel *)model;
  106. [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:goodModel.img]placeholderImage:[UIImage imageNamed:placholderImg]];
  107. self.goodLabel.text = goodModel.title;
  108. NSString *priceString = [NSString stringWithFormat:@"¥%@",goodModel.discount_price];
  109. NSMutableAttributedString *mutableAttPrice = [[NSMutableAttributedString alloc] initWithString:priceString attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Medium" size: 18]}];
  110. [mutableAttPrice addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size: 12]} range:[priceString rangeOfString:@"¥"]];
  111. self.priceLabel.attributedText = mutableAttPrice;
  112. NSString *disCountPrice = [NSString stringWithFormat:@"¥%@",goodModel.price];
  113. NSAttributedString *disCounrAtt = [[NSAttributedString alloc] initWithString:disCountPrice attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x999999],NSFontAttributeName:FONT_SYS(12),NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle)}];
  114. self.disCountPriceLabel.attributedText = disCounrAtt;
  115. self.quanLabel.text = goodModel.coupon_price;
  116. if ([goodModel.coupon_price integerValue] == 0) {
  117. self.quanImageView.hidden = YES;
  118. } else{
  119. self.quanImageView.hidden = NO;
  120. }
  121. self.profitLabel.text = goodModel.commission_rate;
  122. }
  123. - (void)layoutSubviews{
  124. [super layoutSubviews];
  125. }
  126. - (UIImageView *)quanImageView{
  127. if (!_quanImageView) {
  128. _quanImageView = [[UIImageView alloc] init];
  129. _quanImageView.image = [UIImage imageNamed:@"coupon_icon"];
  130. UILabel *quanLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 16)];
  131. quanLabel.textColor = [UIColor whiteColor];
  132. quanLabel.font = FONT_SYS(12);
  133. quanLabel.text = @"券";
  134. quanLabel.textAlignment = NSTextAlignmentCenter;
  135. [_quanImageView addSubview:quanLabel];
  136. }
  137. return _quanImageView;
  138. }
  139. @end