热更新demo

relateNewsCell.m 6.8KB

    // // relateNewsCell.m // ThePaperHD // // Created by scar1900 on 15/5/13. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "relateNewsCell.h" #import "AsyncImageView.h" #define tableWidht rect_screen.size.width @interface relateNewsCell() { CGFloat contentHeight; } @property(nonatomic, strong)UIView *backView; @property(nonatomic, strong)UILabel *contentLabel; @property(nonatomic, strong)AsyncImageView *newsImageView; @property(nonatomic, strong)UIView *lineView; @property(nonatomic, strong)UIImageView *videoIcon; @end @implementation relateNewsCell @synthesize listBO = _listBO; - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // self.selectionStyle = UITableViewCellSelectionStyleGray; // self.selectedBackgroundView = self.selectView; self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; [self.contentView addSubview:self.backView]; [self.backView addSubview:self.contentLabel]; [self.backView addSubview:self.newsImageView]; [self.backView addSubview:self.lineView]; [self.backView addSubview:self.videoIcon]; UIView *selectView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, CGRectGetWidth(self.bounds)-20, CGRectGetHeight(self.bounds))]; selectView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.selectedBackgroundView = selectView; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } return self; } - (void)needrefreshNightMode:(id)sender{ self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; _backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; _contentLabel.textColor = [UIColor colorWithHexString:TextBlack]; _lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; UIView *selectView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, CGRectGetWidth(self.bounds)-20, CGRectGetHeight(self.bounds))]; selectView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.selectedBackgroundView = selectView; [self.contentLabel setNeedsDisplay]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (AsyncImageView *)newsImageView { if (nil == _newsImageView) { _newsImageView = [[AsyncImageView alloc] initWithFrame:CGRectZero]; _newsImageView.backgroundColor = [UIColor clearColor]; } return _newsImageView; } - (UIImageView *)videoIcon { if (nil == _videoIcon) { _videoIcon = [[UIImageView alloc] initWithFrame:CGRectZero]; _videoIcon.image = Image(@"detailPage/vedioIcon_detail.png"); _videoIcon.hidden = YES; } return _videoIcon; } //- (UIView *)selectView { // if (!_selectView) { // _selectView = [[UIView alloc]initWithFrame:CGRectZero]; // _selectView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; // } // return _selectView; //} - (void)setListBO:(listContObjectVO *)data { _listBO = data; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSString *imageId = getImageNameFromURL(data.pic); int readmode = [[TPUserDefault instance].readModeStr intValue]; if (readmode == intelligentMode) { if ([Remote IsEnableWIFI]) { readmode = imageMode; }else { readmode = textMode; } } dispatch_async(dispatch_get_main_queue(), ^{ self.contentLabel.text = data.name; self.newsImageView.imageUrl = data.pic; self.newsImageView.imageId = imageId; [self layoutSubViews:readmode]; if ([data.watermark isEqualToString:@"1"]) { self.videoIcon.hidden = NO; }else { self.videoIcon.hidden = YES; } }); }); // self.timeLabel.text = data.pubTime; } - (UIView *)backView { if (!_backView) { _backView = [[UIView alloc]initWithFrame:CGRectZero]; _backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } return _backView; } - (UILabel *)contentLabel { if (!_contentLabel) { _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableWidht-96, 0)]; _contentLabel.font = appFont(TEXT_THREE_LEVELSIZE, NO); _contentLabel.textColor = [UIColor colorWithHexString:TextBlack]; _contentLabel.textAlignment = NSTextAlignmentLeft; _contentLabel.numberOfLines = 2; _contentLabel.lineBreakMode = NSLineBreakByTruncatingTail; _contentLabel.backgroundColor = [UIColor clearColor]; } return _contentLabel; } - (UIView*)lineView { if (!_lineView) { _lineView = [[UIView alloc]initWithFrame:CGRectZero]; _lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _lineView; } - (void)layoutSubViews:(int)readMode{ int readmode = [[TPUserDefault instance].readModeStr intValue]; if (readmode == intelligentMode) { if ([Remote IsEnableWIFI]) { readmode = imageMode; }else { readmode = textMode; } } if (readmode == imageMode) { contentHeight = [self.contentLabel sizeThatFits:CGSizeMake(tableWidht-96, CGFLOAT_MAX)].height; /** * bug:5114(话题详情页,相关新闻的新闻标题只显示了一行) */ self.backView.frame = CGRectMake(10, 0, tableWidht-20, 60); self.newsImageView.frame = CGRectMake(tableWidht-10-70, 0, 60, 60); // self.selectView.frame = self.backView.frame; self.videoIcon.frame = CGRectMake(tableWidht-10-70+15, 15, 30, 30); self.contentLabel.frame = CGRectMake(8, 8, tableWidht-96, contentHeight); self.lineView.frame = CGRectMake(0, 59, tableWidht-80, 1); }else { contentHeight = [self.contentLabel sizeThatFits:CGSizeMake(tableWidht-36, CGFLOAT_MAX)].height; self.backView.frame = CGRectMake(10, 0, tableWidht-20, 60); self.newsImageView.frame = CGRectMake(0, 0, 0, 0); // self.selectView.frame = self.backView.frame; self.contentLabel.frame = CGRectMake(8, 8, tableWidht-36, contentHeight); self.lineView.frame = CGRectMake(0, 59, tableWidht-20, 1); } } - (void)awakeFromNib { // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end