猎豆优选

LDModelCollectionCell.m 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // LDModelCollectionCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/7/11.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDModelCollectionCell.h"
  9. @interface LDModelCollectionCell()
  10. @property (nonatomic, strong) UIImageView *iconView;
  11. @property (nonatomic, strong) YYLabel *priceLabel;
  12. @property (nonatomic, strong) YYLabel *disPrice;
  13. @property (nonatomic, strong) UILabel *commissionLabel;
  14. @end
  15. @implementation LDModelCollectionCell
  16. - (instancetype)initWithFrame:(CGRect)frame {
  17. self = [super initWithFrame:frame];
  18. if (self) {
  19. self.layer.cornerRadius = 6;
  20. [self initSubViews];
  21. }
  22. return self;
  23. }
  24. - (void)initSubViews {
  25. [self.contentView addSubview:self.iconView];
  26. [self.contentView addSubview:self.titleLabel];
  27. [self.contentView addSubview:self.priceLabel];
  28. [self.contentView addSubview:self.disPrice];
  29. [self.iconView addSubview:self.commissionLabel];
  30. [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.top.mas_equalTo(0);
  32. make.right.mas_equalTo(0);
  33. make.left.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:(LDChildGoodModel *)model {
  54. _model = model;
  55. // [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:Placehold_Img];
  56. [self.iconView sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:Placehold_Img options:0 progress:nil completed:nil];
  57. self.titleLabel.text = model.title;
  58. self.disPrice.text = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
  59. NSString *price=[NSString stringWithFormat:@"%.2f",[model.price floatValue]];
  60. NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:price];
  61. YYTextDecoration *decoration = [YYTextDecoration decorationWithStyle:YYTextLineStyleSingle width:@1 color:[UIColor YHColorWithHex:0x999999]];
  62. [attri yy_setTextStrikethrough:decoration range:NSMakeRange(0, price.length)];
  63. attri.yy_color = [UIColor YHColorWithHex:0x999999];
  64. self.priceLabel.attributedText = attri;
  65. //预估佣金视图
  66. if (model.commission_price.length > 0) {
  67. self.commissionLabel.text = [NSString stringWithFormat:@"预估佣金¥%.2f",[model.commission_price floatValue]];
  68. self.commissionLabel.hidden = NO;
  69. }else {
  70. self.commissionLabel.hidden = YES;
  71. }
  72. }
  73. #pragma mark --- layzer ---
  74. - (UIImageView *)iconView {
  75. if (!_iconView) {
  76. _iconView = [[UIImageView alloc] init];
  77. _iconView.backgroundColor = [UIColor whiteColor];
  78. _iconView.layer.cornerRadius = 5;
  79. _iconView.layer.masksToBounds = YES;
  80. }
  81. return _iconView;
  82. }
  83. - (YYLabel *)titleLabel {
  84. if (!_titleLabel) {
  85. _titleLabel = [[YYLabel alloc] init];
  86. _titleLabel.numberOfLines = 1;
  87. _titleLabel.displaysAsynchronously = YES;
  88. _titleLabel.textColor = [UIColor YHColorWithHex:0x333333];
  89. _titleLabel.font = [UIFont systemFontOfSize:Fitsize(13)];
  90. }
  91. return _titleLabel;
  92. }
  93. - (YYLabel *)priceLabel {
  94. if (!_priceLabel) {
  95. _priceLabel = [[YYLabel alloc] init];
  96. _priceLabel.displaysAsynchronously = YES;
  97. _priceLabel.textColor = [UIColor YHColorWithHex:0x999999];
  98. _priceLabel.font = [UIFont systemFontOfSize:Fitsize(11)];
  99. _priceLabel.textAlignment = NSTextAlignmentRight;
  100. }
  101. return _priceLabel;
  102. }
  103. - (YYLabel *)disPrice {
  104. if (!_disPrice) {
  105. _disPrice = [[YYLabel alloc] init];
  106. _disPrice.displaysAsynchronously = YES;
  107. _disPrice.font = [UIFont systemFontOfSize:Fitsize(14)];
  108. _disPrice.textColor = [UIColor homeRedColor];
  109. }
  110. return _disPrice;
  111. }
  112. - (UILabel *)commissionLabel {
  113. if (!_commissionLabel) {
  114. _commissionLabel = [[UILabel alloc] init];
  115. _commissionLabel.font = [UIFont systemFontOfSize:11];
  116. _commissionLabel.textColor = [UIColor whiteColor];
  117. _commissionLabel.textAlignment = NSTextAlignmentCenter;
  118. _commissionLabel.backgroundColor = [UIColor homeRedColor];
  119. }
  120. return _commissionLabel;
  121. }
  122. @end