No Description

FKProBrandCell.m 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // FKProBrandCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/8/13.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKProBrandCell.h"
  9. #import "FKProDetailViewModel.h"
  10. @interface FKProBrandCell ()
  11. @property (nonatomic, strong) UIImageView *brandImgView;
  12. @property (nonatomic, strong) UILabel *brandLabel;
  13. @property (nonatomic, strong) UILabel *countLabel;
  14. @property (nonatomic, strong) UILabel *contentLabel;
  15. //@property (nonatomic, strong) MASConstraint *widthConst;
  16. @end
  17. @implementation FKProBrandCell
  18. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  19. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  20. [self addAllSubviews];
  21. self.selectionStyle = UITableViewCellSelectionStyleNone;
  22. self.contentView.backgroundColor = [UIColor whiteColor];
  23. }
  24. return self;
  25. }
  26. - (void)addAllSubviews{
  27. [self.contentView addSubview:self.brandImgView];
  28. [self.contentView addSubview:self.bookButton];
  29. [self.contentView addSubview:self.brandLabel];
  30. [self.contentView addSubview:self.countLabel];
  31. [self.contentView addSubview:self.contentLabel];
  32. [self.contentView addSubview:self.brandButton];
  33. [self.contentView addSubview:self.arrowBtn];
  34. [self.brandImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.top.equalTo(self.contentView).offset(15);
  36. make.left.equalTo(self.contentView).offset(15);
  37. make.size.mas_equalTo(CGSizeMake(41, 41));
  38. }];
  39. [self.brandButton mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.center.equalTo(self.brandImgView);
  41. make.size.mas_equalTo(CGSizeMake(50, 50));
  42. }];
  43. [self.bookButton mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.right.equalTo(self.contentView).offset(- 15);
  45. make.centerY.equalTo(self.brandImgView);
  46. make.size.mas_equalTo(CGSizeMake(55, 22));
  47. }];
  48. [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.top.equalTo(self.brandImgView.mas_bottom).offset(10);
  50. make.left.equalTo(self.contentView).offset(15);
  51. make.right.equalTo(self.contentView).offset(-35);
  52. make.bottom.equalTo(self.contentView).offset(-10);
  53. }];
  54. [self.arrowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.centerY.equalTo(self.contentLabel.mas_bottom).offset(- 15);
  56. make.centerX.equalTo(self.contentView.mas_right).offset(- 20);
  57. make.size.mas_equalTo(CGSizeMake(40, 40));
  58. }];
  59. }
  60. + (CGFloat)cellHeightForContent:(NSString *)content{
  61. if (![FLStringHelper isValidString:content]) return 66;
  62. CGFloat contentH = [FLStringHelper sizeOfAttributeString:content
  63. lineSpace:2.4
  64. width:UISCREENWIDTH - 50
  65. font:[UIFont systemFontOfSize:13]
  66. maxRow:NSIntegerMax].height;
  67. return contentH + 77;
  68. }
  69. - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
  70. if ([viewModel isKindOfClass:[FKProDetailViewModel class]]) {
  71. FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel;
  72. [self.brandImgView setImageWithURL:detailModel.brandRecItem.brandInfo.picUrl cdnWidth:41];
  73. NSString *countTip = [FKProBrandCell validProductCountTip:detailModel.brandRecItem.brandInfo.validProdCount];
  74. if (countTip) {
  75. [self.brandLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  76. make.left.equalTo(self.brandImgView.mas_right).offset(7);
  77. make.centerY.equalTo(self.brandImgView).offset(-8);
  78. }];
  79. [self.countLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  80. make.left.equalTo(self.brandImgView.mas_right).offset(7);
  81. make.centerY.equalTo(self.brandImgView).offset(8);
  82. }];
  83. } else {
  84. [self.brandLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  85. make.left.equalTo(self.brandImgView.mas_right).offset(7);
  86. make.centerY.equalTo(self.brandImgView);
  87. }];
  88. }
  89. self.brandLabel.text = detailModel.brandRecItem.brandInfo.brandName;
  90. self.countLabel.text = countTip;
  91. self.bookButton.selected = detailModel.brandRecItem.brandInfo.hasBook;
  92. NSAttributedString *attM = [FLStringHelper attStringWithText:detailModel.brandRecItem.brandInfo.desc lineSpace:2.4];
  93. self.contentLabel.attributedText = attM;
  94. NSString *arrowImgName = detailModel.isBrandDescClose ? @"brandDownArrow" : @"brandUpArrow";
  95. [_arrowBtn setImage:[UIImage imageNamed:arrowImgName] forState:UIControlStateNormal];
  96. }
  97. }
  98. #pragma mark - Private Method
  99. + (NSString *)validProductCountTip:(NSString *)countString {
  100. if (countString.integerValue >= 10) {
  101. NSString *text = countString;
  102. if (countString.integerValue >= 10000) {
  103. text = [NSString stringWithFormat:@"%ldw+", countString.integerValue/10000];
  104. }
  105. return [NSString stringWithFormat:@"%@件畅销商品", text];;
  106. }
  107. return nil;
  108. }
  109. #pragma mark - property
  110. - (UIImageView *)brandImgView{
  111. if (_brandImgView == nil) {
  112. _brandImgView = [[UIImageView alloc]init];
  113. _brandImgView.layer.borderWidth = 0.5;
  114. _brandImgView.layer.borderColor = UIColorFromRGB(0xe5e5e5).CGColor;
  115. _brandImgView.contentMode = UIViewContentModeScaleAspectFit;
  116. }
  117. return _brandImgView;
  118. }
  119. - (UILabel *)brandLabel{
  120. if (_brandLabel == nil) {
  121. _brandLabel = [[UILabel alloc]init];
  122. _brandLabel.textColor = UIColorFromRGB(0x333333);
  123. _brandLabel.font = [UIFont systemFontOfSize:13];
  124. }
  125. return _brandLabel;
  126. }
  127. - (UILabel *)countLabel {
  128. if (_countLabel == nil) {
  129. _countLabel = [[UILabel alloc]init];
  130. _countLabel.textAlignment = NSTextAlignmentLeft;
  131. _countLabel.textColor = UIColorFromRGB(0x999999);
  132. _countLabel.font = [UIFont systemFontOfSize:12];
  133. }
  134. return _countLabel;
  135. }
  136. - (UIButton *)brandButton{
  137. if (_brandButton == nil) {
  138. _brandButton = [UIButton buttonWithType:UIButtonTypeCustom];
  139. }
  140. return _brandButton;
  141. }
  142. - (UIButton *)bookButton{
  143. if (_bookButton == nil) {
  144. _bookButton = [UIButton buttonWithType:UIButtonTypeCustom];
  145. [_bookButton setTitle:@"+ 订阅" forState:UIControlStateNormal];
  146. [_bookButton setTitle:@"取消订阅" forState:UIControlStateSelected];
  147. [_bookButton setTitleColor:UIColorFromRGB(0xff624a) forState:UIControlStateNormal];
  148. [_bookButton setTitleColor:UIColorFromRGB(0xcccccc) forState:UIControlStateSelected];
  149. _bookButton.layer.cornerRadius = 11.0f;
  150. _bookButton.layer.borderWidth = 0.5;
  151. _bookButton.layer.borderColor = UIColorFromRGB(0xcccccc).CGColor;
  152. _bookButton.layer.masksToBounds = YES;
  153. _bookButton.titleLabel.font = [UIFont systemFontOfSize:10];
  154. _bookButton.selected = NO;
  155. }
  156. return _bookButton;
  157. }
  158. - (UILabel *)contentLabel{
  159. if (_contentLabel == nil) {
  160. _contentLabel = [[UILabel alloc]init];
  161. _contentLabel.textColor = UIColorFromRGB(0x666666);
  162. _contentLabel.font = [UIFont systemFontOfSize:13];
  163. _contentLabel.numberOfLines = 0;
  164. }
  165. return _contentLabel;
  166. }
  167. - (UIButton *)arrowBtn {
  168. if (!_arrowBtn) {
  169. _arrowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  170. }
  171. return _arrowBtn;
  172. }
  173. @end