酷店

KDPSupplyGoodCollectionViewCell.m 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.adjustsFontSizeToFitWidth = YES;
  64. self.profitLabel.textAlignment = NSTextAlignmentLeft;
  65. [self.contenAView addSubview:self.profitLabel];
  66. }
  67. - (void)setSubViewsConstraints{
  68. [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.top.left.right.equalTo(self.contentView);
  70. make.height.equalTo(173);
  71. }];
  72. [self.goodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.equalTo(self.contentView.mas_left).offset(10);
  74. make.right.equalTo(self.contentView.mas_right).offset(-6);
  75. make.top.equalTo(self.iconImageView.mas_bottom).offset(11);
  76. make.height.equalTo(21);
  77. }];
  78. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.left.equalTo(self.contentView.mas_left).offset(10);
  80. make.top.equalTo(self.goodLabel.mas_bottom).offset(7);
  81. }];
  82. [self.disCountPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.left.equalTo(self.priceLabel.mas_right).offset(2);
  84. make.centerY.equalTo(self.priceLabel);
  85. }];
  86. [self.quanImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.centerY.equalTo(self.priceLabel);
  88. make.right.equalTo(self.contentView.mas_right).offset(-6);
  89. make.size.equalTo(CGSizeMake(50, 16));
  90. }];
  91. [self.quanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.right.top.bottom.equalTo(self.quanImageView);
  93. make.width.equalTo(40);
  94. }];
  95. [self.contenAView mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.left.equalTo(self.contentView.mas_left).offset(10);
  97. make.top.equalTo(self.priceLabel.mas_bottom).offset(7);
  98. make.size.equalTo(CGSizeMake(78, 26));
  99. }];
  100. [self.profitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.right.top.bottom.equalTo(self.contenAView);
  102. make.width.equalTo(39);
  103. }];
  104. }
  105. - (void)configCellWithModel:(id)model indexPath:(NSIndexPath *)indexpath{
  106. KDPGoodsModel *goodModel = (KDPGoodsModel *)model;
  107. [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:goodModel.img]placeholderImage:[UIImage imageNamed:placholderImg]];
  108. self.goodLabel.text = goodModel.title;
  109. NSString *priceString = [NSString stringWithFormat:@"¥%@",goodModel.discount_price];
  110. NSMutableAttributedString *mutableAttPrice = [[NSMutableAttributedString alloc] initWithString:priceString attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Medium" size: 18]}];
  111. [mutableAttPrice addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size: 12]} range:[priceString rangeOfString:@"¥"]];
  112. self.priceLabel.attributedText = mutableAttPrice;
  113. NSString *disCountPrice = [NSString stringWithFormat:@"¥%@",goodModel.price];
  114. NSAttributedString *disCounrAtt = [[NSAttributedString alloc] initWithString:disCountPrice attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x999999],NSFontAttributeName:FONT_SYS(12),NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle)}];
  115. self.disCountPriceLabel.attributedText = disCounrAtt;
  116. self.quanLabel.text = goodModel.coupon_price;
  117. if ([goodModel.coupon_price integerValue] == 0) {
  118. self.quanImageView.hidden = YES;
  119. } else{
  120. self.quanImageView.hidden = NO;
  121. }
  122. self.profitLabel.text = goodModel.commission_rate;
  123. }
  124. - (void)layoutSubviews{
  125. [super layoutSubviews];
  126. }
  127. - (UIImageView *)quanImageView{
  128. if (!_quanImageView) {
  129. _quanImageView = [[UIImageView alloc] init];
  130. _quanImageView.image = [UIImage imageNamed:@"coupon_icon"];
  131. UILabel *quanLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 16)];
  132. quanLabel.textColor = [UIColor whiteColor];
  133. quanLabel.font = FONT_SYS(12);
  134. quanLabel.text = @"券";
  135. quanLabel.textAlignment = NSTextAlignmentCenter;
  136. [_quanImageView addSubview:quanLabel];
  137. }
  138. return _quanImageView;
  139. }
  140. @end