No Description

FKHomeFollowInfoCell.m 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // FKHomeFollowInfoCell.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/8/13.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKHomeFollowInfoCell.h"
  9. #import "FKHomeViewModel.h"
  10. @interface FKHomeFollowSingleView : UIView
  11. @property (nonatomic, strong) UILabel *countLabel;
  12. @property (nonatomic, strong) UILabel *titleLabel;
  13. @property (nonatomic, strong) UIView *separatorLine;
  14. @end
  15. @implementation FKHomeFollowSingleView
  16. - (instancetype)initWithFrame:(CGRect)frame{
  17. if (self = [super initWithFrame:frame]) {
  18. [self addAllSubviews];
  19. }
  20. return self;
  21. }
  22. - (void)addAllSubviews {
  23. [self addSubview:self.countLabel];
  24. [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.bottom.equalTo(self.mas_centerY).offset(-1);
  26. make.centerX.equalTo(self);
  27. }];
  28. [self addSubview:self.titleLabel];
  29. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.top.equalTo(self.mas_centerY).offset(1);
  31. make.centerX.equalTo(self);
  32. }];
  33. [self addSubview:self.separatorLine];
  34. [self.separatorLine mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.centerY.equalTo(self);
  36. make.height.mas_equalTo(20);
  37. make.width.mas_equalTo(1.0/[UIScreen mainScreen].scale);
  38. }];
  39. }
  40. #pragma mark - property
  41. - (UILabel *)countLabel {
  42. if (!_countLabel) {
  43. _countLabel = [UILabel new];
  44. _countLabel.font = [UIFont boldSystemFontOfSize:18];
  45. _countLabel.textColor = UIColorFromRGB(0x333333);
  46. _countLabel.textAlignment = NSTextAlignmentCenter;
  47. }
  48. return _countLabel;
  49. }
  50. - (UILabel *)titleLabel {
  51. if (!_titleLabel) {
  52. _titleLabel = [UILabel new];
  53. _titleLabel.font = [UIFont systemFontOfSize:13];
  54. _titleLabel.textColor = UIColorFromRGB(0x666666);
  55. _titleLabel.textAlignment = NSTextAlignmentCenter;
  56. }
  57. return _titleLabel;
  58. }
  59. - (UIView *)separatorLine {
  60. if (!_separatorLine) {
  61. _separatorLine = [UIView new];
  62. _separatorLine.backgroundColor = UIColorFromRGB(0xdddddd);
  63. }
  64. return _separatorLine;
  65. }
  66. @end
  67. #pragma mark - ****** FKHomeFollowInfoCell ******
  68. @interface FKHomeFollowInfoCell ()
  69. @property (nonatomic, strong) NSMutableArray<FKHomeFollowSingleView*> *viewArray;
  70. @property (nonatomic, strong) NSArray *textArray;
  71. @end
  72. static const NSInteger FOLLOWELEMENTCOUNT = 3;
  73. @implementation FKHomeFollowInfoCell
  74. - (void)awakeFromNib {
  75. [super awakeFromNib];
  76. // Initialization code
  77. }
  78. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  79. [super setSelected:selected animated:animated];
  80. // Configure the view for the selected state
  81. }
  82. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  83. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  84. self.selectionStyle = UITableViewCellSelectionStyleNone;
  85. [self addAllSubviews];
  86. }
  87. return self;
  88. }
  89. - (void)fk_configWithViewModel:(FKHomeViewModel *)viewModel indexPath:(NSIndexPath *)indexPath {
  90. FKHomeFollowSingleView *view;
  91. NSArray *countArray = @[[FLStringHelper replaceNilWithEmpty:viewModel.countModel.priceRemindCount],
  92. [FLStringHelper replaceNilWithEmpty:viewModel.countModel.collectProductCount],
  93. [FLStringHelper replaceNilWithEmpty:viewModel.countModel.subscribeBrandCount]];
  94. for (int idx = 0; idx < FOLLOWELEMENTCOUNT && countArray.count; idx++) {
  95. view = self.viewArray[idx];
  96. view.countLabel.text = countArray[idx];
  97. if (![FKUserManager isUserLogin]) {
  98. view.countLabel.text = @"0";
  99. }
  100. }
  101. }
  102. #pragma mark - Action
  103. - (IBAction)clickViewGesture:(UIGestureRecognizer *)gesture {
  104. if (self.delegate && [self.delegate respondsToSelector:@selector(followClickCell:index:)]) {
  105. [self.delegate followClickCell:self index:gesture.view.tag];
  106. }
  107. }
  108. #pragma mark - Layout
  109. - (void)addAllSubviews {
  110. CGFloat width = (int)(UISCREENWIDTH/FOLLOWELEMENTCOUNT);
  111. FKHomeFollowSingleView *view;
  112. for (int idx = 0; idx < FOLLOWELEMENTCOUNT && self.textArray.count; idx++) {
  113. view = [FKHomeFollowSingleView new];
  114. view.frame = CGRectMake(width*idx, 0, width, [FKHomeFollowInfoCell height]);
  115. view.tag = idx;
  116. view.separatorLine.hidden = (idx == 0 ? TRUE : FALSE);
  117. [view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickViewGesture:)]];
  118. view.titleLabel.text = self.textArray[idx];
  119. [self.contentView addSubview:view];
  120. [self.viewArray addObject:view];
  121. }
  122. }
  123. + (CGFloat)height {
  124. return 60;
  125. }
  126. #pragma mark - Property
  127. - (NSMutableArray *)viewArray{
  128. if (!_viewArray) {
  129. _viewArray = [NSMutableArray array];
  130. }
  131. return _viewArray;
  132. }
  133. - (NSArray *)textArray{
  134. if (!_textArray) {
  135. _textArray = @[@"关注的降价", @"收藏的商品", @"订阅的品牌"];
  136. }
  137. return _textArray;
  138. }
  139. @end