热更新demo

liveContTitleCell.m 3.4KB

    // // liveContTitleCell.m // ThePaperHD // // Created by scar1900 on 15/3/11. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "liveContTitleCell.h" #define CONTENTWIDTH rect_screen.size.width-60 @interface liveContTitleCell() { CGFloat titleHeight; } @property(nonatomic, strong)UILabel *titleLabel; @property(nonatomic, strong)UILabel *timeLabel; @end @implementation liveContTitleCell @synthesize dataDic = _dataDic; @synthesize isFirst; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; [self addSubview:self.titleLabel]; [self addSubview:self.timeLabel]; self.isFirst = YES; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } return self; } - (void)needrefreshNightMode:(id)sender{ self.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; _titleLabel.textColor = [UIColor colorWithHexString:TextBlack]; _timeLabel.textColor = [UIColor colorWithHexString:BLUECOLOR]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)setDataDic:(NSDictionary *)dic { _dataDic = dic; NSAttributedString *title = dic[@"title"]; if (!isBlankString(dic[@"date"])) { self.timeLabel.text = dic[@"date"]; self.timeLabel.hidden = NO; }else { self.timeLabel.hidden = YES; } self.titleLabel.attributedText = title; titleHeight = [self.titleLabel sizeThatFits:CGSizeMake(CONTENTWIDTH, CGFLOAT_MAX)].height; [self layoutSubViews]; } - (UILabel*)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, CONTENTWIDTH, 0)]; _titleLabel.backgroundColor = [UIColor clearColor]; _titleLabel.textAlignment = NSTextAlignmentLeft; _titleLabel.textColor = [UIColor colorWithHexString:TextBlack]; _titleLabel.lineBreakMode = NSLineBreakByWordWrapping; _titleLabel.numberOfLines = 0; } return _titleLabel; } - (UILabel *)timeLabel { if (!_timeLabel) { _timeLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _timeLabel.textColor = [UIColor colorWithHexString:BLUECOLOR]; _timeLabel.backgroundColor = [UIColor clearColor]; _timeLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); } return _timeLabel; } - (void)layoutSubViews { [self.titleLabel remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.left).offset(50); make.top.equalTo(self.top).offset(10); make.width.mas_equalTo(CONTENTWIDTH); make.height.mas_equalTo(titleHeight); }]; [self.timeLabel remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.left).offset(10); make.top.equalTo(self.top).offset(13); make.width.mas_equalTo(32); make.height.mas_equalTo(10); }]; [super layoutSubviews]; } - (void)awakeFromNib { // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end