Ei kuvausta

FKCircleProductCell.m 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // FKCircleProductCell.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/6/14.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKCircleProductCell.h"
  9. #import <SDWebImage/UIImageView+WebCache.h>
  10. #import "FKCircleChoiceProductItem.h"
  11. @interface FKCircleProductCell ()
  12. @property (nonatomic, strong) UIImageView *productImgView;
  13. @property (nonatomic, strong) UILabel *titleLabel;
  14. @property (nonatomic, strong) UILabel *currentPriceLabel;
  15. @property (nonatomic, strong) UILabel *originPriceLabel;
  16. @property (nonatomic, strong) UIView *cutLine;
  17. @end
  18. @implementation FKCircleProductCell
  19. - (void)awakeFromNib {
  20. [super awakeFromNib];
  21. // Initialization code
  22. }
  23. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  24. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  25. if (self) {
  26. self.contentView.backgroundColor = [UIColor whiteColor];
  27. [self addAllSubviews];
  28. }
  29. return self;
  30. }
  31. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  32. [super setSelected:selected animated:animated];
  33. // Configure the view for the selected state
  34. }
  35. - (void)configWithItem:(id)item {
  36. if ([item isKindOfClass:[FKCircleChoiceProductItem class]]) {
  37. FKCircleChoiceProductItem *productItem = (FKCircleChoiceProductItem*)item;
  38. [self.productImgView sd_setImageWithURL:[NSURL URLWithString:productItem.photoURL]];
  39. self.titleLabel.text = productItem.title;
  40. self.currentPriceLabel.text = [FLStringHelper convertFenToRMBmoneyString:productItem.price];
  41. self.originPriceLabel.text = nil;
  42. if ([FLStringHelper isValidString:productItem.originPrice]){
  43. self.originPriceLabel.text = [FLStringHelper convertFenToRMBmoneyString:productItem.originPrice];
  44. }
  45. self.choiceButton.selected = productItem.isSelected;
  46. }
  47. }
  48. #pragma mark - Method
  49. + (CGFloat)height {
  50. return 105;
  51. }
  52. #pragma mark - Layout
  53. - (void)addAllSubviews {
  54. [self.contentView addSubview:self.productImgView];
  55. [self.productImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.centerY.equalTo(self.contentView);
  57. make.left.equalTo(self.contentView).offset(5);
  58. make.size.mas_equalTo(CGSizeMake(95, 95));
  59. }];
  60. [self.contentView addSubview:self.titleLabel];
  61. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.left.equalTo(self.productImgView.mas_right).offset(10);
  63. make.top.equalTo(self.contentView).offset(20);
  64. make.right.equalTo(self.contentView).offset(-15);
  65. }];
  66. [self.contentView addSubview:self.currentPriceLabel];
  67. [self.currentPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.left.equalTo(self.titleLabel);
  69. make.bottom.equalTo(self.contentView).offset(-22);
  70. }];
  71. [self.contentView addSubview:self.choiceButton];
  72. [self.choiceButton mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.right.equalTo(self.contentView).offset(-15);
  74. make.centerY.equalTo(self.currentPriceLabel);
  75. make.size.mas_equalTo(CGSizeMake(30, 30));
  76. }];
  77. [self.contentView addSubview:self.originPriceLabel];
  78. [self.originPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.left.equalTo(self.currentPriceLabel.mas_right).offset(2);
  80. make.baseline.equalTo(self.currentPriceLabel.mas_baseline);
  81. make.right.mas_lessThanOrEqualTo(self.choiceButton.mas_left);
  82. }];
  83. [self.contentView addSubview:self.cutLine];
  84. [self.cutLine mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.center.equalTo(self.originPriceLabel);
  86. make.width.mas_equalTo(self.originPriceLabel);
  87. make.height.mas_equalTo(0.5);
  88. }];
  89. }
  90. #pragma mark - Property
  91. - (UIImageView*)productImgView {
  92. if (!_productImgView) {
  93. _productImgView = [UIImageView new];
  94. _productImgView.contentMode = UIViewContentModeScaleAspectFit;
  95. _productImgView.backgroundColor = [UIColor whiteColor];
  96. }
  97. return _productImgView;
  98. }
  99. - (UILabel *)titleLabel {
  100. if (!_titleLabel) {
  101. _titleLabel = [[UILabel alloc] init];
  102. _titleLabel.textColor = UIColorFromRGB(0x333333);
  103. _titleLabel.font = [UIFont systemFontOfSize:14];
  104. _titleLabel.numberOfLines = 2;
  105. }
  106. return _titleLabel;
  107. }
  108. - (UILabel *)currentPriceLabel{
  109. if (_currentPriceLabel == nil) {
  110. _currentPriceLabel = [[UILabel alloc]init];
  111. _currentPriceLabel.textColor = UIColorFromRGB(0x333333);
  112. _currentPriceLabel.font = [UIFont boldSystemFontOfSize:15];
  113. }
  114. return _currentPriceLabel;
  115. }
  116. - (UILabel *)originPriceLabel{
  117. if (_originPriceLabel == nil) {
  118. _originPriceLabel = [[UILabel alloc]init];
  119. _originPriceLabel.font = [UIFont boldSystemFontOfSize:9];
  120. _originPriceLabel.textColor = UIColorFromRGB(0x666666);
  121. _originPriceLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  122. }
  123. return _originPriceLabel;
  124. }
  125. - (UIButton *)choiceButton{
  126. if (_choiceButton == nil) {
  127. _choiceButton = [UIButton buttonWithType:UIButtonTypeCustom];
  128. [_choiceButton setImage:[UIImage imageNamed:@"basket_unSelect"] forState:UIControlStateNormal];
  129. [_choiceButton setImage:[UIImage imageNamed:@"basket_selected"] forState:UIControlStateSelected];
  130. }
  131. return _choiceButton;
  132. }
  133. - (UIView *)cutLine{
  134. if (_cutLine == nil) {
  135. _cutLine = [[UIView alloc]init];
  136. _cutLine.backgroundColor = UIColorFromRGB(0x666666);
  137. }
  138. return _cutLine;
  139. }
  140. @end