口袋优选

KBScrollChildCollectionViewCell.m 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // KBScrollChildCollectionViewCell.m
  3. // YouHuiProject
  4. //
  5. // Created by xiaoxi on 2018/1/17.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBScrollChildCollectionViewCell.h"
  9. @implementation KBScrollChildCollectionViewCell
  10. - (instancetype)initWithFrame:(CGRect)frame {
  11. self = [super initWithFrame:frame];
  12. if (self) {
  13. [self initSubviews];
  14. }
  15. return self;
  16. }
  17. - (void)initSubviews {
  18. [self.contentView.layer addSublayer:self.pictureLayer];
  19. [self.contentView addSubview:self.topLabel];
  20. [self.contentView addSubview:self.middleLabel];
  21. [self.contentView addSubview:self.bottomLabel];
  22. [self.contentView addSubview:self.priceLabel];
  23. [_topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  24. make.left.equalTo(self.contentView).offset(FITSIZE(10));
  25. make.top.equalTo(self.contentView).offset(FITSIZE(195));
  26. make.right.equalTo(self.contentView).offset(-FITSIZE(10));
  27. }];
  28. [_middleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.left.equalTo(_topLabel);
  30. make.top.equalTo(_topLabel.mas_bottom).offset(FITSIZE(15));
  31. make.right.equalTo(_topLabel);
  32. }];
  33. [_bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.left.equalTo(_middleLabel);
  35. make.top.equalTo(_middleLabel.mas_bottom).offset(FITSIZE(15));
  36. make.right.equalTo(_middleLabel);
  37. }];
  38. [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.right.equalTo(self.contentView).offset(-FITSIZE(10));
  40. make.centerY.equalTo(_bottomLabel);
  41. }];
  42. }
  43. - (void)setModel:(KBChildGoodModel *)model {
  44. _model = model;
  45. [self.pictureLayer yy_setImageWithURL:[NSURL URLWithString:model.img] placeholder:Placehold_Img options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation completion:nil];
  46. NSMutableAttributedString *topAttStr = [[NSMutableAttributedString alloc] initWithString:model.title];
  47. NSTextAttachment *attach = [[NSTextAttachment alloc] init];
  48. if ([model.freeShipping boolValue]) {
  49. attach.image = [UIImage imageNamed:@"Rectangle"];
  50. attach.bounds = CGRectMake(0, -1, 26, 13);
  51. [topAttStr insertAttributedString:[NSAttributedString attributedStringWithAttachment:attach] atIndex:0];
  52. }
  53. self.topLabel.attributedText = topAttStr;
  54. self.middleLabel.text = [NSString stringWithFormat:@"月销 %@", model.volume];
  55. NSAttributedString *bottomAttStr = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"原价 ¥%.2f", model.price.floatValue] attributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle)}];
  56. self.bottomLabel.attributedText = bottomAttStr;
  57. self.priceLabel.text = [NSString stringWithFormat:@"¥ %.2f", model.discount_price.floatValue];
  58. }
  59. #pragma mark - lazy
  60. - (CALayer *)pictureLayer {
  61. if (!_pictureLayer) {
  62. _pictureLayer = [CALayer layer];
  63. _pictureLayer.backgroundColor = [UIColor clearColor].CGColor;
  64. _pictureLayer.frame = CGRectMake(0, 0, FITSIZE(185), FITSIZE(185));
  65. }
  66. return _pictureLayer;
  67. }
  68. - (UILabel *)topLabel {
  69. if (!_topLabel) {
  70. _topLabel = [[UILabel alloc] init];
  71. _topLabel.backgroundColor = [UIColor clearColor];
  72. _topLabel.textColor = [UIColor YHColorWithHex:0x444444];
  73. _topLabel.font = [UIFont systemFontOfSize:FITSIZE(14)];
  74. }
  75. return _topLabel;
  76. }
  77. - (UILabel *)middleLabel {
  78. if (!_middleLabel) {
  79. _middleLabel = [[UILabel alloc] init];
  80. _middleLabel.backgroundColor = [UIColor clearColor];
  81. _middleLabel.textColor = [UIColor YHColorWithHex:0x999999];
  82. _middleLabel.font = [UIFont systemFontOfSize:FITSIZE(10)];
  83. }
  84. return _middleLabel;
  85. }
  86. - (UILabel *)bottomLabel {
  87. if (!_bottomLabel) {
  88. _bottomLabel = [[UILabel alloc] init];
  89. _bottomLabel.backgroundColor = [UIColor clearColor];
  90. _bottomLabel.textColor = [UIColor YHColorWithHex:0x888888];
  91. _bottomLabel.font = [UIFont systemFontOfSize:FITSIZE(12)];
  92. }
  93. return _bottomLabel;
  94. }
  95. - (UILabel *)priceLabel {
  96. if (!_priceLabel) {
  97. _priceLabel = [[UILabel alloc] init];
  98. _priceLabel.backgroundColor = [UIColor clearColor];
  99. _priceLabel.textColor = [UIColor YHColorWithHex:0xff2420];
  100. _priceLabel.font = [UIFont boldSystemFontOfSize:FITSIZE(18)];
  101. }
  102. return _priceLabel;
  103. }
  104. @end