123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- //
- // FKHomeFollowInfoCell.m
- // FirstLink
- //
- // Created by ascii on 16/8/13.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKHomeFollowInfoCell.h"
- #import "FKHomeViewModel.h"
- @interface FKHomeFollowSingleView : UIView
- @property (nonatomic, strong) UILabel *countLabel;
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UIView *separatorLine;
- @end
- @implementation FKHomeFollowSingleView
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- [self addAllSubviews];
- }
- return self;
- }
- - (void)addAllSubviews {
- [self addSubview:self.countLabel];
- [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self.mas_centerY).offset(-1);
- make.centerX.equalTo(self);
- }];
-
- [self addSubview:self.titleLabel];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.mas_centerY).offset(1);
- make.centerX.equalTo(self);
- }];
-
- [self addSubview:self.separatorLine];
- [self.separatorLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.centerY.equalTo(self);
- make.height.mas_equalTo(20);
- make.width.mas_equalTo(1.0/[UIScreen mainScreen].scale);
- }];
- }
- #pragma mark - property
- - (UILabel *)countLabel {
- if (!_countLabel) {
- _countLabel = [UILabel new];
- _countLabel.font = [UIFont boldSystemFontOfSize:18];
- _countLabel.textColor = UIColorFromRGB(0x333333);
- _countLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _countLabel;
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [UILabel new];
- _titleLabel.font = [UIFont systemFontOfSize:13];
- _titleLabel.textColor = UIColorFromRGB(0x666666);
- _titleLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _titleLabel;
- }
- - (UIView *)separatorLine {
- if (!_separatorLine) {
- _separatorLine = [UIView new];
- _separatorLine.backgroundColor = UIColorFromRGB(0xdddddd);
- }
- return _separatorLine;
- }
- @end
- #pragma mark - ****** FKHomeFollowInfoCell ******
- @interface FKHomeFollowInfoCell ()
- @property (nonatomic, strong) NSMutableArray<FKHomeFollowSingleView*> *viewArray;
- @property (nonatomic, strong) NSArray *textArray;
- @end
- static const NSInteger FOLLOWELEMENTCOUNT = 3;
- @implementation FKHomeFollowInfoCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
- self.selectionStyle = UITableViewCellSelectionStyleNone;
-
- [self addAllSubviews];
- }
- return self;
- }
- - (void)fk_configWithViewModel:(FKHomeViewModel *)viewModel indexPath:(NSIndexPath *)indexPath {
- FKHomeFollowSingleView *view;
- NSArray *countArray = @[[FLStringHelper replaceNilWithEmpty:viewModel.countModel.priceRemindCount],
- [FLStringHelper replaceNilWithEmpty:viewModel.countModel.collectProductCount],
- [FLStringHelper replaceNilWithEmpty:viewModel.countModel.subscribeBrandCount]];
- for (int idx = 0; idx < FOLLOWELEMENTCOUNT && countArray.count; idx++) {
- view = self.viewArray[idx];
- view.countLabel.text = countArray[idx];
-
- if (![FKUserManager isUserLogin]) {
- view.countLabel.text = @"0";
- }
- }
- }
- #pragma mark - Action
- - (IBAction)clickViewGesture:(UIGestureRecognizer *)gesture {
- if (self.delegate && [self.delegate respondsToSelector:@selector(followClickCell:index:)]) {
- [self.delegate followClickCell:self index:gesture.view.tag];
- }
- }
- #pragma mark - Layout
- - (void)addAllSubviews {
- CGFloat width = (int)(UISCREENWIDTH/FOLLOWELEMENTCOUNT);
-
- FKHomeFollowSingleView *view;
- for (int idx = 0; idx < FOLLOWELEMENTCOUNT && self.textArray.count; idx++) {
- view = [FKHomeFollowSingleView new];
- view.frame = CGRectMake(width*idx, 0, width, [FKHomeFollowInfoCell height]);
- view.tag = idx;
- view.separatorLine.hidden = (idx == 0 ? TRUE : FALSE);
- [view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickViewGesture:)]];
-
- view.titleLabel.text = self.textArray[idx];
-
- [self.contentView addSubview:view];
- [self.viewArray addObject:view];
- }
- }
- + (CGFloat)height {
- return 60;
- }
- #pragma mark - Property
- - (NSMutableArray *)viewArray{
- if (!_viewArray) {
- _viewArray = [NSMutableArray array];
- }
- return _viewArray;
- }
- - (NSArray *)textArray{
- if (!_textArray) {
- _textArray = @[@"关注的降价", @"收藏的商品", @"订阅的品牌"];
- }
- return _textArray;
- }
- @end
|