热更新demo

myFocusCell.m 13KB

    // // myFocusCell.m // ThePaperBase // // Created by YoungLee on 15/8/19. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "myFocusCell.h" @interface myFocusCell(){ CGFloat topHeight; int contentHeight; CGFloat nameWidth; CGFloat answerWidth; CGFloat ansHeight; } @property(nonatomic ,strong)UILabel *markLabel; @end @implementation myFocusCell @synthesize commentBO = _commentBO; @synthesize indexPath = _indexPath; - (void)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{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.selectionStyle = UITableViewCellSelectionStyleNone; self.clipsToBounds = YES; [self.contentView addSubview:self.backView]; [self.backView addSubview:self.topLabel]; [self.backView addSubview:self.line]; [self.backView addSubview:self.name]; [self.backView addSubview:self.nameButton]; [self.backView addSubview:self.answerNum]; [self.backView addSubview:self.topBtn]; [self.backView addSubview:self.content]; [self.backView addSubview:self.contentBtn]; [self.contentView addSubview:self.markLabel]; [self.backView addSubview:self.shadowLine]; [self subLayoutSubviews]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } return self; } - (void)needrefreshNightMode:(id)sender{ self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.topLabel.textColor = [UIColor colorWithHexString:TextLightGray]; self.line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; self.name.textColor = [UIColor colorWithHexString:BLUECOLOR]; self.answerNum.textColor = [UIColor colorWithHexString:TextBlack]; [self.answerNum setNeedsDisplay]; self.content.textColor = [UIColor colorWithHexString:TextGray]; self.shadowLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } -(UIView *)backView{ if (!_backView) { _backView = [UIView new]; _backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } return _backView; } -(UILabel *)topLabel{ if (!_topLabel) { _topLabel = [UILabel new]; _topLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO); _topLabel.textColor = [UIColor colorWithHexString:TextLightGray]; _topLabel.numberOfLines = 0; _topLabel.lineBreakMode = NSLineBreakByWordWrapping; _topLabel.backgroundColor = [UIColor clearColor]; } return _topLabel; } -(UIView *)line{ if (!_line) { _line = [UIView new]; _line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _line; } -(UILabel *)name{ if (!_name) { _name = [UILabel new]; _name.textColor = [UIColor colorWithHexString:BLUECOLOR]; _name.font = appFont(TEXT_SIX_LEVELSIZE, NO); _name.backgroundColor = [UIColor clearColor]; } return _name; } -(UIView *)shadowLine{ if (!_shadowLine) { _shadowLine = [UIView new]; _shadowLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _shadowLine; } -(RTLabel *)answerNum{ if (!_answerNum) { _answerNum = [[RTLabel alloc] initWithFrame:CGRectZero]; _answerNum.textColor = [UIColor colorWithHexString:TextBlack]; _answerNum.lineSpacing = 2; _answerNum.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); _answerNum.backgroundColor = [UIColor clearColor]; } return _answerNum; } -(TPEmojiLabel *)content{ if (!_content) { _content = [[TPEmojiLabel alloc] initWithFrame:CGRectMake(0, 0, rect_screen.size.width-20, 0) LineSpace:10 ParagraphSpacing:0]; _content.textAlignment = NSTextAlignmentLeft; _content.lineBreakMode = NSLineBreakByWordWrapping; _content.textColor = [UIColor colorWithHexString:TextGray]; _content.font = appFont(TEXT_FOUR_LEVELSIZE, NO); } return _content; } -(UIButton *)topBtn{ if (!_topBtn) { _topBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_topBtn addTarget:self action:@selector(topSelector:) forControlEvents:UIControlEventTouchUpInside]; _topBtn.backgroundColor = [UIColor clearColor]; } return _topBtn; } -(UIButton *)contentBtn{ if (!_contentBtn) { _contentBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_contentBtn addTarget:self action:@selector(contentSelector:) forControlEvents:UIControlEventTouchUpInside]; _contentBtn.backgroundColor = [UIColor clearColor]; } return _contentBtn; } -(UIButton *)nameButton{ if (!_nameButton) { _nameButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_nameButton addTarget:self action:@selector(nameSelector:) forControlEvents:UIControlEventTouchUpInside]; _nameButton.backgroundColor = [UIColor clearColor]; } return _nameButton; } - (UILabel*)markLabel { if (!_markLabel) { _markLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _markLabel.backgroundColor = [UIColor colorWithHexString:@"0xc32128"]; _markLabel.layer.cornerRadius = 15/2; _markLabel.clipsToBounds = YES; _markLabel.textAlignment = NSTextAlignmentCenter; _markLabel.textColor = [UIColor whiteColor]; _markLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); _markLabel.hidden = YES; } return _markLabel; } #pragma mark -- btn handler -(void) topSelector:(UIButton*)btn{ if ([self.delegate respondsToSelector:@selector(pushContent:)]) { [self.delegate pushContent:_commentBO]; } } -(void) contentSelector:(UIButton*)btn{ if ([self.delegate respondsToSelector:@selector(pushToAskInfo:index:)]) { [self.delegate pushToAskInfo:_commentBO index:_indexPath]; } } -(void)nameSelector:(UIButton*) btn{ if ([self.delegate respondsToSelector:@selector(pushToUserInfo:)]) { [self.delegate pushToUserInfo:self.commentBO]; } } -(void)setCommentBO:(commentObjectVO *)bo{ _commentBO = bo; NSString *topTitle; if([_commentBO.objectType intValue] == 3){ topTitle = [NSString stringWithFormat:@"【原话题】%@",_commentBO.contName]; }else{ topTitle = [NSString stringWithFormat:@"【原新闻】%@",_commentBO.contName]; } self.topLabel.attributedText = getLineSpaceAttributedString(topTitle, 2, appFont(TEXT_SIX_LEVELSIZE, NO)); userBO *user = setJsonDicToDataModel(_commentBO.userInfo, [userBO class]); NSString *nameStr; if([user.userId intValue] == [[TPUserDefault instance].userBO.userId intValue]){ nameStr = @"我:"; }else{ nameStr = user.sname?[NSString stringWithFormat:@"%@:",user.sname]:@""; } self.name.text = nameStr; self.answerNum.text = [NSString stringWithFormat:@"<font color='#00a5eb'>%@</font><N>个回答",_commentBO.answerNums]; self.content.text = _commentBO.content; NSString *newNum = _commentBO.unNums; if ([newNum intValue] >0 ) { if ([newNum intValue] > 9) { self.markLabel.text = @"9+"; }else{ self.markLabel.text = newNum; } self.markLabel.hidden = NO; }else { self.markLabel.hidden = YES; self.markLabel.text = @"0"; } topHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(topTitle, 2, appFont(TEXT_SIX_LEVELSIZE, NO)), rect_screen.size.width -40, appFont(TEXT_SIX_LEVELSIZE, NO)); contentHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width - 40 Text:_commentBO.content LineSpace:10 ParagraphSpacing:0]; answerWidth = returnTextWidthWithRTLabel(self.answerNum.text, 15, self.answerNum.font, 10); ansHeight = returnTextHeightWithRTLabel(self.answerNum.text, answerWidth+5, self.answerNum.font, 2); nameWidth = 10+widthForString(self.name.text, self.name.font, 15, self.name.lineBreakMode); [self remakeSubViews]; } -(void)subLayoutSubviews{ if (self.isEditing) { [self sendSubviewToBack:self.contentView]; } [self.backView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.left).offset(10); make.right.equalTo(self.contentView.right).offset(-10); make.top.equalTo(self.contentView.top).offset(10); make.bottom.equalTo(self.contentView.bottom); }]; [self.markLabel makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.backView.right).offset(15/2); make.width.equalTo(@15); make.top.equalTo(self.backView.top).offset(-15/2); make.height.equalTo(@15); }]; [self.topLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left).offset(5); make.right.equalTo(self.backView.right).offset(-15); make.top.equalTo(self.backView.top); make.height.mas_equalTo(25); }]; [self.topBtn makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.topLabel); }]; [self.line makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left); make.right.equalTo(self.backView.right); make.bottom.equalTo(self.topLabel.bottom); make.height.equalTo(@0.5); }]; [self.name makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left).offset(10); make.width.equalTo(@250); make.top.equalTo(self.line.bottom).offset(10); make.height.equalTo(@15); }]; [self.answerNum makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.right).offset(-answerWidth-12); make.width.mas_equalTo(answerWidth+5); make.top.equalTo(self.name.top).offset(3); make.height.equalTo(ansHeight); }]; [self.content makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left).offset(10); make.right.equalTo(self.backView.right).offset(-10); make.top.equalTo(self.name.bottom).offset(8); make.height.mas_equalTo(25); }]; [self.contentBtn makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.content); }]; [self.shadowLine makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left); make.right.equalTo(self.backView.right); make.top.equalTo(self.backView.bottom).offset(-1); make.height.mas_equalTo(1); }]; } - (void)remakeSubViews { [self.topLabel remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left).offset(5); make.right.equalTo(self.backView.right).offset(-15); make.top.equalTo(self.backView.top).offset(5); make.height.mas_equalTo(topHeight); }]; [self.line remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left); make.right.equalTo(self.backView.right); make.bottom.equalTo(self.topLabel.bottom).offset(5); make.height.equalTo(@0.5); }]; [self.name remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left).offset(10); make.width.mas_equalTo(nameWidth); make.top.equalTo(self.line.bottom).offset(10); make.height.equalTo(@15); }]; [self.nameButton makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.name.left).offset(-5); make.right.equalTo(self.name.right).offset(5); make.top.equalTo(self.name.top).offset(-5); make.bottom.equalTo(self.name.bottom).offset(5); }]; [self.answerNum remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.right).offset(-answerWidth-12); make.width.mas_equalTo(answerWidth+5); make.top.equalTo(self.name.top).offset(3); make.height.equalTo(ansHeight); }]; [self.content remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left).offset(10); make.right.equalTo(self.backView.right).offset(-10); make.top.equalTo(self.name.bottom).offset(8); make.height.equalTo(contentHeight); }]; } @end