口袋优选

KBModuleCollectionCell.m 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // KBModuleCollectionCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/7/4.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBModuleCollectionCell.h"
  9. @interface KBModuleCollectionCell()
  10. @property (nonatomic, strong) UIImageView *iconView;
  11. @property (nonatomic, strong) UILabel *titleLabel;
  12. @property (nonatomic, strong) UILabel *priceLabel;
  13. @property (nonatomic, strong) UILabel *disPrice;
  14. @property (nonatomic, strong) UILabel *commissionLabel;
  15. @end
  16. @implementation KBModuleCollectionCell
  17. - (instancetype)initWithFrame:(CGRect)frame {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. self.layer.cornerRadius = 6;
  21. self.layer.masksToBounds = YES;
  22. [self initSubViews];
  23. }
  24. return self;
  25. }
  26. - (void)initSubViews {
  27. [self.contentView addSubview:self.iconView];
  28. [self.contentView addSubview:self.titleLabel];
  29. [self.contentView addSubview:self.priceLabel];
  30. [self.contentView addSubview:self.disPrice];
  31. [self.iconView addSubview:self.commissionLabel];
  32. [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.top.left.right.mas_equalTo(0);
  34. make.height.mas_equalTo(self.iconView.mas_width);
  35. }];
  36. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.right.mas_equalTo(0);
  38. make.top.mas_equalTo(self.iconView.mas_bottom).mas_offset(Fitsize(10));
  39. }];
  40. [self.disPrice mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.left.mas_equalTo(0);
  42. make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(Fitsize(6));
  43. }];
  44. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.left.mas_equalTo(self.disPrice.mas_right).mas_offset(3);
  46. make.bottom.mas_equalTo(self.disPrice.mas_bottom).mas_offset(-1);
  47. }];
  48. [self.commissionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.left.right.bottom.mas_offset(0);
  50. make.height.mas_equalTo(20);
  51. }];
  52. }
  53. - (void)setModel:(KBChildGoodModel *)model {
  54. _model = model;
  55. [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:Placehold_Img];
  56. self.titleLabel.text = model.title;
  57. self.disPrice.text = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
  58. NSString *price=[NSString stringWithFormat:@"%.2f",[model.price floatValue]];
  59. NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:price];
  60. [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, price.length)];
  61. [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor YHColorWithHex:0x999999] range:NSMakeRange(0, price.length)];
  62. self.priceLabel.attributedText = attri;
  63. }
  64. #pragma mark --- layzer ---
  65. - (UIImageView *)iconView {
  66. if (!_iconView) {
  67. _iconView = [[UIImageView alloc] init];
  68. _iconView.backgroundColor = [UIColor yhGrayColor];
  69. _iconView.layer.cornerRadius = 5;
  70. _iconView.layer.masksToBounds = YES;
  71. }
  72. return _iconView;
  73. }
  74. - (UILabel *)titleLabel {
  75. if (!_titleLabel) {
  76. _titleLabel = [[UILabel alloc] init];
  77. _titleLabel.numberOfLines = 1;
  78. _titleLabel.textColor = [UIColor YHColorWithHex:0x333333];
  79. _titleLabel.font = [UIFont systemFontOfSize:Fitsize(12)];
  80. }
  81. return _titleLabel;
  82. }
  83. - (UILabel *)priceLabel {
  84. if (!_priceLabel) {
  85. _priceLabel = [[UILabel alloc] init];
  86. _priceLabel.textColor = [UIColor YHColorWithHex:0x999999];
  87. _priceLabel.font = [UIFont systemFontOfSize:Fitsize(11)];
  88. }
  89. return _priceLabel;
  90. }
  91. - (UILabel *)disPrice {
  92. if (!_disPrice) {
  93. _disPrice = [[UILabel alloc] init];
  94. _disPrice.font = [UIFont systemFontOfSize:Fitsize(15)];
  95. _disPrice.textColor = [UIColor homeRedColor];
  96. }
  97. return _disPrice;
  98. }
  99. - (UILabel *)commissionLabel {
  100. if (!_commissionLabel) {
  101. _commissionLabel = [[UILabel alloc] init];
  102. _commissionLabel.font = [UIFont systemFontOfSize:11];
  103. _commissionLabel.textColor = [UIColor whiteColor];
  104. _commissionLabel.textAlignment = NSTextAlignmentCenter;
  105. _commissionLabel.backgroundColor = [UIColor changeColor];
  106. _commissionLabel.hidden = YES;
  107. }
  108. return _commissionLabel;
  109. }
  110. @end