123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- //
- // HSQTimeLineTableCell.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/12/27.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "HSQTimeLineTableCell.h"
- #import "HSQTimeLineCommentView.h"
- #import "UIView+SDAutoLayout.h"
- #import "CCCopyLabel.h"
- @interface HSQTimeLineTableCell ()
- @property (nonatomic, strong) UIImageView *iconView;
- @property (nonatomic, strong) UILabel *name;
- @property (nonatomic, strong) CCCopyLabel *title;
- @property (nonatomic, strong) UIView *goodBg;
- @property (nonatomic, strong) UIImageView *goodIcon;
- @property (nonatomic, strong) UILabel *goodTitle;
- @property (nonatomic, strong) UILabel *disPrice;
- //@property (nonatomic, strong) UILabel *localLabel;
- @property (nonatomic, strong) UILabel *timeLabel;
- @property (nonatomic, strong) UIButton *shareButton;
- //@property (nonatomic, strong) HSQTimeLineCommentView *commentView;
- @property (nonatomic, strong) UIImageView *ticketNumber; //
- @property (nonatomic, strong) UILabel *zheKou; // 几折,或者几元券
- @property (nonatomic, strong) UILabel *ticketType;
- @property (nonatomic, strong) UIView *tapView;
- @end
- @implementation HSQTimeLineTableCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- + (instancetype)cellWithTableView:(UITableView *)tableView {
- static NSString *cellID = nil;
- cellID = NSStringFromClass([self class]);
- HSQTimeLineTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
- if (!cell) {
- cell = [[HSQTimeLineTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- return cell;
-
- }
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self initSubViews];
- }
- return self;
- }
- - (void)initSubViews {
- [self.contentView addSubview:self.iconView];
- [self.contentView addSubview:self.name];
- [self.contentView addSubview:self.title];
- [self.contentView addSubview:self.goodBg];
-
- [self.goodBg addSubview:self.goodIcon];
- [self.goodBg addSubview:self.goodTitle];
- [self.goodBg addSubview:self.disPrice];
- [self.goodBg addSubview:self.ticketNumber];
- [self.goodBg addSubview:self.tapView];
- [self.ticketNumber addSubview:self.ticketType];
- [self.ticketNumber addSubview:self.zheKou];
-
- // [self.contentView addSubview:self.localLabel];
- [self.contentView addSubview:self.timeLabel];
- [self.contentView addSubview:self.shareButton];
-
- // [self.contentView addSubview:self.commentView];
-
- [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.top.mas_equalTo(14);
- make.width.height.mas_equalTo(42);
- }];
-
- [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.iconView.mas_right).mas_offset(10);
- make.top.mas_equalTo(17);
- make.right.mas_equalTo(-10);
- }];
-
- [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.name.mas_bottom).mas_offset(7);
- make.left.mas_equalTo(self.name);
- make.right.mas_equalTo(-10);
- }];
-
- [self.goodBg mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.name);
- make.right.mas_equalTo(-10);
- make.top.mas_equalTo(self.title.mas_bottom).mas_offset(7);
- make.height.mas_equalTo(90);
- }];
-
- [self.tapView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
- }];
-
- // [self.localLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.left.mas_equalTo(self.goodBg);
- // make.right.mas_equalTo(-10);
- // make.top.mas_equalTo(self.goodBg.mas_bottom).mas_offset(8);
- // }];
-
- [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.goodBg);
- make.top.mas_equalTo(self.goodBg.mas_bottom).mas_offset(8);
- make.right.mas_equalTo(-10);
- }];
-
- [self.shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(-10);
- make.centerY.mas_equalTo(self.timeLabel.mas_centerY);
- make.width.mas_equalTo(50);
- make.height.mas_equalTo(20);
- }];
-
- [self.goodIcon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.mas_equalTo(5);
- make.width.height.mas_equalTo(80);
- }];
-
- [self.goodTitle mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.goodIcon.mas_right).mas_offset(7);
- make.right.mas_equalTo(-7);
- make.top.mas_equalTo(self.goodIcon.mas_top).mas_offset(4);
- }];
-
- [self.disPrice mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.goodTitle);
- make.centerY.mas_equalTo(self.goodIcon.mas_centerY);
- }];
-
- [self.ticketNumber mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.goodTitle.mas_left);
- make.width.mas_equalTo(64);
- make.height.mas_equalTo(14);
- make.bottom.mas_equalTo(-10);
- }];
-
- [self.ticketType mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.bottom.mas_equalTo(0);
- make.width.mas_equalTo(20);
- }];
-
- [self.zheKou mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.ticketType.mas_right);
- make.top.mas_equalTo(0);
- make.height.mas_equalTo(14);
- make.width.mas_equalTo(44);
- }];
-
-
-
- // _commentView.sd_layout
- // .leftEqualToView(self.name)
- // .rightSpaceToView(self.contentView, 10)
- // .topSpaceToView(_timeLabel, 10);
- }
- - (void)shareClick {
- if (self.shareClickBlock) {
- self.shareClickBlock();
- }
- }
- -(void)setLineSpace:(CGFloat)lineSpace withText:(NSString *)text inLabel:(UILabel *)label{
- if (!text || !label) {
- return;
- }
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- paragraphStyle.lineSpacing = lineSpace; //设置行间距
- paragraphStyle.lineBreakMode = label.lineBreakMode;
- // paragraphStyle.alignment = label.textAlignment;
-
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
- [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
- label.attributedText = attributedString;
- }
- - (void)setModel:(HSQTimeLineModel *)model {
- _model = model;
- [self.iconView sd_setFadeImageWithURL:[NSURL URLWithString:model.subscribe_img] placeholderImage:nil options:0 progress:nil completed:nil];
- self.name.text = model.subscribe_title;
- // self.title.text = model.show_content;
- [self setLineSpace:4 withText:model.show_content inLabel:self.title];
- [self.goodIcon sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil];;
- self.goodTitle.text = model.title;
- self.disPrice.text = [NSString stringWithFormat:@"¥%@",model.discount_price];
- self.timeLabel.text = model.pass_time;
- // self.localLabel.text = model.location;
-
- //折后价
- NSString *disStr;
- if ([model.is_coupon boolValue]) {
- disStr = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
- self.zheKou.text = [NSString stringWithFormat:@"%@元",model.coupon_price];
- self.ticketType.text = @"券";
- }else {
- disStr = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
- self.zheKou.text = [NSString stringWithFormat:@"%@折",model.coupon_price];
- self.ticketType.text = @"折";
- }
-
- //券相关
- self.ticketNumber.hidden = ![model.is_coupon boolValue];
-
- UIView *bottomView;
- bottomView = _timeLabel;
- // [self.commentView setupWithLikeItemsArray:model.shareUser contentText:model.show_comment];
- // if (!model.shareUser.count && model.show_comment.length==0) {
- // bottomView = _timeLabel;
- // } else {
- // bottomView = _commentView;
- // }
- [self setupAutoHeightWithBottomView:bottomView bottomMargin:15];
- }
- - (void)tapAction {
- if (self.tapBlock) {
- self.tapBlock();
- }
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (UIImageView *)iconView {
- if (!_iconView) {
- _iconView = [[UIImageView alloc] init];
- _iconView.layer.cornerRadius = 21;
- _iconView.layer.masksToBounds = YES;
- _iconView.backgroundColor = [UIColor yhGrayColor];
- }
- return _iconView;
- }
- - (UILabel *)name {
- if (!_name) {
- _name = [[UILabel alloc] init];
- _name.font = [UIFont boldSystemFontOfSize:17];
- _name.textColor = [UIColor YHColorWithHex:0x576B95];
- }
- return _name;
- }
- - (CCCopyLabel *)title {
- if (!_title) {
- _title = [[CCCopyLabel alloc] init];
- _title.font = [UIFont fontWithName:@"HelveticaNeue" size:17];
- _title.textColor = [UIColor YHColorWithHex:0x222222];
- _title.numberOfLines = 0;
- _title.longTapBlock = ^{
- [MobClick event:OptimizingCircleCopyTopContent];
- };
- }
- return _title;
- }
- - (UIView *)goodBg {
- if (!_goodBg) {
- _goodBg = [[UIView alloc] init];
- _goodBg.backgroundColor = [UIColor YHColorWithHex:0xF3F3F5 alpha:0.9];
- }
- return _goodBg;
- }
- //- (UILabel *)localLabel {
- // if (!_localLabel) {
- // _localLabel = [[UILabel alloc] init];
- // _localLabel.font = [UIFont systemFontOfSize:14];
- // _localLabel.textColor = [UIColor YHColorWithHex:0x576B95];
- // }
- // return _localLabel;
- //}
- - (UILabel *)timeLabel {
- if (!_timeLabel) {
- _timeLabel = [[UILabel alloc] init];
- _timeLabel.font = [UIFont systemFontOfSize:14];
- _timeLabel.textColor = [UIColor YHColorWithHex:0xB2B2B2];
-
- }
- return _timeLabel;
- }
- - (UIButton *)shareButton {
- if (!_shareButton) {
- _shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [_shareButton setTitle:@"分享" forState:UIControlStateNormal];
- _shareButton.layer.cornerRadius = 10;
- _shareButton.layer.borderColor = [UIColor YHColorWithHex:0x576B95].CGColor;
- _shareButton.layer.borderWidth = 1;
- [_shareButton setTitleColor:[UIColor YHColorWithHex:0x576B95] forState:UIControlStateNormal];
- _shareButton.titleLabel.font = [UIFont systemFontOfSize:11];
- [_shareButton addTarget:self action:@selector(shareClick) forControlEvents:UIControlEventTouchUpInside];
- }
- return _shareButton;
- }
- - (UIImageView *)goodIcon {
- if (!_goodIcon) {
- _goodIcon = [[UIImageView alloc] init];
- _goodIcon.backgroundColor = [UIColor whiteColor];
- }
- return _goodIcon;
- }
- - (UILabel *)goodTitle {
- if (!_goodTitle) {
- _goodTitle = [[UILabel alloc] init];
- _goodTitle.font = [UIFont systemFontOfSize:14];
- _goodTitle.textColor = [UIColor blackColor];
- }
- return _goodTitle;
- }
- - (UILabel *)disPrice {
- if (!_disPrice) {
- _disPrice = [[UILabel alloc] init];
- _disPrice.textColor = [UIColor homeRedColor];
- _disPrice.font = [UIFont systemFontOfSize:16];
- }
- return _disPrice;
- }
- //- (HSQTimeLineCommentView *)commentView {
- // if (!_commentView) {
- // _commentView = [HSQTimeLineCommentView new];
- // }
- // return _commentView;
- //}
- - (UIImageView *)ticketNumber {
- if (!_ticketNumber) {
- _ticketNumber = [[UIImageView alloc] init];
- _ticketNumber.image = [UIImage imageNamed:@"tickY"];
- }
- return _ticketNumber;
- }
- - (UILabel *)zheKou {
- if (!_zheKou) {
- _zheKou = [[UILabel alloc] init];
- _zheKou.textColor = [UIColor homeRedColor];
- _zheKou.textAlignment = NSTextAlignmentCenter;
- _zheKou.font = [UIFont systemFontOfSize:10];
- }
- return _zheKou;
- }
- - (UILabel *)ticketType {
- if (!_ticketType) {
- _ticketType = [[UILabel alloc] init];
- _ticketType.font = [UIFont systemFontOfSize:10];
- _ticketType.textAlignment = NSTextAlignmentCenter;
- _ticketType.textColor = [UIColor homeRedColor];
- }
- return _ticketType;
- }
- - (UIView *)tapView {
- if (!_tapView) {
- _tapView = [[UIView alloc] init];
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
- [_tapView addGestureRecognizer:tap];
- }
- return _tapView;
- }
- @end
|