// // topicDescCell.m // ThePaperHD // // Created by scar1900 on 15/5/12. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "topicDescCell.h" #define tableWidht rect_screen.size.width @interface topicDescCell() { CGFloat descHeight; } @property(nonatomic, strong)UIView *backView; @property(nonatomic, strong)UIView *line; @property(nonatomic, strong)UIButton *expandBtn; @property(nonatomic, strong)UILabel *kindLabel; @property(nonatomic, strong)UILabel *timeLabel; @property(nonatomic, strong)UIImageView *timeImg; @end @implementation topicDescCell @synthesize topicDesc = _topicDesc; @synthesize expand; @synthesize delegate; - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.selectionStyle = UITableViewCellSelectionStyleNone; self.contentView.backgroundColor = [UIColor clearColor]; self.backgroundColor = [UIColor clearColor]; [self.contentView addSubview:self.backView]; [self.backView addSubview:self.descLabel]; [self.backView addSubview:self.expandBtn]; [self.backView addSubview:self.line]; [self.backView addSubview:self.timeLabel]; [self.backView addSubview:self.timeImg]; [self.backView addSubview:self.kindLabel]; self.expand = NO; [self layoutViews]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } return self; } - (void)needrefreshNightMode:(id)sender{ _backView.backgroundColor =[UIColor colorWithHexString:BackGroundColor]; _descLabel.textColor = [UIColor colorWithHexString:TextGray]; _line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; _timeLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _kindLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _kindLabel.layer.borderColor = [UIColor colorWithHexString:LIGHTGRAY].CGColor; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)setTopicDesc:(NSString *)str { _topicDesc = str; // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ descHeight = returnTextHeightWithRTLabel(str, tableWidht-20, appFont(TEXT_FIVE_LEVELSIZE, NO), 7); // dispatch_async(dispatch_get_main_queue(), ^{ if (descHeight > TOPIC_FOUR_LINE_HEIGHT) { if (!self.expand) { descHeight = descHeight>TOPIC_FOUR_LINE_HEIGHT?TOPIC_FOUR_LINE_HEIGHT:descHeight; } self.descLabel.userInteractionEnabled = YES; self.expandBtn.hidden = NO; }else { self.expandBtn.hidden = YES; self.descLabel.userInteractionEnabled = NO; } self.descLabel.text = str; [self relayoutSubViews]; // }); // }); // CGFloat oneLine = returnTextHeightWithRTLabel(@"高度", 100, appFont(TEXT_FIVE_LEVELSIZE, NO), 7); } - (void)setTimeStr:(NSString *)timeStr { self.timeLabel.text = timeStr; } - (void)setKindStr:(NSString *)kindStr { self.kindLabel.text = kindStr; } - (UILabel *)kindLabel { if (!_kindLabel) { _kindLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 20)]; _kindLabel.backgroundColor = [UIColor clearColor]; _kindLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO); _kindLabel.layer.borderWidth = 0.5; _kindLabel.layer.cornerRadius = 1; _kindLabel.layer.masksToBounds = YES; _kindLabel.textAlignment = NSTextAlignmentCenter; _kindLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _kindLabel.layer.borderColor = [UIColor colorWithHexString:LIGHTGRAY].CGColor; } return _kindLabel; } - (UIView *)backView { if (!_backView) { _backView = [[UIView alloc] initWithFrame:CGRectZero]; _backView.backgroundColor =[UIColor colorWithHexString:BackGroundColor]; } return _backView; } - (UILabel *)timeLabel { if (!_timeLabel) { _timeLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _timeLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _timeLabel.backgroundColor = [UIColor clearColor]; _timeLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); } return _timeLabel; } - (UIImageView *)timeImg { if (!_timeImg) { _timeImg = [[UIImageView alloc] initWithFrame:CGRectZero]; _timeImg.image = Image(@"topic/timeImg.png"); } return _timeImg; } - (RTLabel*)descLabel { if (!_descLabel) { _descLabel = [[RTLabel alloc]initWithFrame:CGRectZero]; _descLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO); _descLabel.textColor = [UIColor colorWithHexString:TextGray]; _descLabel.textAlignment = RTTextAlignmentLeft; _descLabel.lineBreakMode = RTTextLineBreakModeCharWrapping; _descLabel.lineSpacing = 7; _descLabel.backgroundColor = [UIColor clearColor]; _descLabel.userInteractionEnabled = YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(expandEvent:)]; [_descLabel addGestureRecognizer:tap]; /** * bug:5184(话题详情页,简介部分,点击文字也要能展开和收缩) */ } return _descLabel; } - (UIButton*)expandBtn { if (!_expandBtn) { _expandBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _expandBtn.backgroundColor = [UIColor clearColor]; _expandBtn.hidden = YES; [_expandBtn setImage:Image(@"detailPage/expandArrow.png") forState:UIControlStateNormal]; [_expandBtn addTarget:self action:@selector(expandEvent:) forControlEvents:UIControlEventTouchUpInside]; } return _expandBtn; } - (UIView*)line { if (!_line) { _line = [[UIView alloc]initWithFrame:CGRectZero]; _line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _line; } - (void)expandEvent:(UIButton*)btn { self.expand = !self.expand; if ([self.delegate respondsToSelector:@selector(clickToExpand:andIndexPath:Cell:)]) { [self.delegate clickToExpand:self.expand andIndexPath:self.indexPath Cell:self]; } } - (void)layoutViews { // self.backView.frame = CGRectMake(0, 0, rect_screen.size.width, CGRectGetHeight(self.contentView.bounds)-10); [self.backView makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView); make.left.equalTo(self.contentView); make.right.equalTo(self.contentView); make.bottom.equalTo(self.contentView).offset(-10); }]; [self.descLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView).offset(10); make.top.equalTo(self.backView).offset(13); make.size.mas_equalTo(CGSizeMake(tableWidht-20, descHeight)); }]; // self.descLabel.frame = CGRectMake(10, 13, tableWidht-20, descHeight); if (!self.expand) { [_expandBtn setImage:Image(@"detailPage/expandArrow.png") forState:UIControlStateNormal]; }else { [_expandBtn setImage:Image(@"detailPage/expandArrowUp.png") forState:UIControlStateNormal]; } // self.expandBtn.frame = CGRectMake(10, // CGRectGetMaxY(self.descLabel.frame), // tableWidht-20, // 30); [self.expandBtn makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView).offset(10); make.top.equalTo(self.descLabel.bottom); make.size.mas_equalTo(CGSizeMake(tableWidht-20, 30)); }]; [self.expandBtn setImageEdgeInsets:UIEdgeInsetsMake(15-15/2, CGRectGetWidth(self.expandBtn.frame)/2-13, 15-15/2, CGRectGetWidth(self.expandBtn.frame)/2-13)]; // self.timeImg.frame = CGRectMake(10, CGRectGetHeight(self.contentView.bounds)-30, 10, 10); [self.timeImg makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView).offset(10); make.top.equalTo(self.backView.bottom).offset(-20); make.size.mas_equalTo(CGSizeMake(10, 10)); }]; // self.timeLabel.frame = CGRectMake(25, CGRectGetHeight(self.contentView.bounds)-30, 150, 10); [self.timeLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView).offset(25); make.top.equalTo(self.backView.bottom).offset(-20); make.size.mas_equalTo(CGSizeMake(150, 10)); }]; // self.kindLabel.frame = CGRectMake(CGRectGetWidth(self.contentView.bounds)-33, CGRectGetHeight(self.contentView.bounds)-30, 23, 11); [self.kindLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.right).offset(-40); make.top.equalTo(self.backView.bottom).offset(-24); make.size.mas_equalTo(CGSizeMake(30, 15)); }]; // self.line.frame = CGRectMake(0, CGRectGetHeight(self.contentView.bounds)-10, tableWidht, 1); [self.line makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView); make.right.equalTo(self.backView); make.bottom.equalTo(self.backView); make.height.mas_equalTo(1); }]; } - (void)relayoutSubViews { [self.descLabel remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView).offset(10); make.top.equalTo(self.backView).offset(13); make.size.mas_equalTo(CGSizeMake(tableWidht-20, descHeight)); }]; // self.descLabel.frame = CGRectMake(10, 13, tableWidht-20, descHeight); if (!self.expand) { [_expandBtn setImage:Image(@"detailPage/expandArrow.png") forState:UIControlStateNormal]; }else { [_expandBtn setImage:Image(@"detailPage/expandArrowUp.png") forState:UIControlStateNormal]; } } - (void)awakeFromNib { // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end