热更新demo

collectContentCell.m 6.9KB

    // // collectCell.m // ThePaperBase // // Created by Huixin on 15/8/30. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "collectContentCell.h" #import "AsyncImageView.h" @interface collectContentCell() { CGFloat titleHeight; } @property(nonatomic, strong)UIView *backView; @property(nonatomic, strong)AsyncImageView *imgView; @property(nonatomic, strong)UILabel *titleLabel; @property(nonatomic, strong)UILabel *bottomLabel; @property(nonatomic, strong)UIView *lineView; @end @implementation collectContentCell - (void)awakeFromNib { // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; UIView *selectView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds))]; selectView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.selectedBackgroundView = selectView; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode) name:REFRESHAFTERNIGHTMODE object:nil]; self.clipsToBounds = YES; [self.contentView addSubview:self.backView]; [self.backView addSubview:self.imgView]; [self.backView addSubview:self.titleLabel]; [self.backView addSubview:self.bottomLabel]; [self.backView addSubview:self.lineView]; [self layoutViews]; } return self; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)needrefreshNightMode { UIView *selectView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds))]; selectView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.selectedBackgroundView = selectView; [self layoutSubviews]; //bug5058: 夜间模式实时切换 } - (void)layoutSubviews { [super layoutSubviews]; self.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; _titleLabel.textColor = [UIColor colorWithHexString:TextBlack]; _bottomLabel.textColor = [UIColor colorWithHexString:TextLightGray]; _lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } - (void)layoutViews { if (self.isEditing) { [self sendSubviewToBack:self.contentView]; } [self.backView makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.contentView); }]; [self.imgView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left).offset(10); make.centerY.equalTo(self.backView.centerY); make.width.and.height.mas_equalTo(@60); }]; [self.titleLabel makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.imgView.top); make.left.equalTo(self.imgView.right).offset(10); make.width.mas_equalTo(rect_screen.size.width-90); make.bottom.equalTo(self.bottomLabel.top); }]; [self.bottomLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.titleLabel.left); make.right.equalTo(self.titleLabel.right); make.bottom.equalTo(self.backView.bottom).offset(-10); make.height.mas_equalTo(@12); }]; [self.lineView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left).offset(10); make.right.equalTo(self.backView.right); make.bottom.equalTo(self.backView.bottom); make.height.mas_equalTo(@1); }]; } - (UIView*)backView { if (!_backView) { _backView = [[UIView alloc] init]; _backView.backgroundColor = [UIColor clearColor]; _backView.clipsToBounds = YES; } return _backView; } - (UIView*)lineView { if (!_lineView) { _lineView = [[UIView alloc] init]; _lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _lineView; } - (AsyncImageView*)imgView { if (!_imgView) { _imgView = [[AsyncImageView alloc] init]; } return _imgView; } - (UILabel*)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.textColor = [UIColor colorWithHexString:TextBlack]; _titleLabel.textAlignment = NSTextAlignmentLeft; _titleLabel.lineBreakMode = NSLineBreakByWordWrapping; _titleLabel.numberOfLines = 0; _titleLabel.backgroundColor = [UIColor clearColor]; } _titleLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); return _titleLabel; } - (UILabel*)bottomLabel { if (!_bottomLabel) { _bottomLabel = [[UILabel alloc] init]; _bottomLabel.textColor = [UIColor colorWithHexString:TextLightGray]; _bottomLabel.textAlignment = NSTextAlignmentRight; _bottomLabel.backgroundColor = [UIColor clearColor]; } _bottomLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO); return _bottomLabel; } - (void)setListBO:(listContObjectVO*)listInfo{ int readmode = [[TPUserDefault instance].readModeStr intValue]; if (readmode == intelligentMode) { if ([Remote IsEnableWIFI]) { readmode = imageMode; }else { readmode = textMode; } } if (readmode == imageMode) { self.imgView.hidden = NO; self.imgView.imageUrl = listInfo.pic; NSString *imageID = getImageNameFromURL(listInfo.pic); self.imgView.imageId = imageID; self.titleLabel.text = listInfo.name; self.bottomLabel.text = [NSString stringWithFormat:@"%@ %@",listInfo.nodeInfo[@"name"],listInfo.pubTime]; titleHeight = [self.titleLabel sizeThatFits:CGSizeMake(rect_screen.size.width-90, 0)].height; [self.titleLabel remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.imgView.top); make.left.equalTo(self.imgView.right).offset(10); make.width.mas_equalTo(rect_screen.size.width-90); make.height.mas_equalTo(titleHeight); }]; } else if (readmode == textMode) { self.imgView.hidden = YES; self.titleLabel.text = listInfo.name; self.bottomLabel.text = [NSString stringWithFormat:@"%@ %@",listInfo.nodeInfo[@"name"],listInfo.pubTime]; titleHeight = [self.titleLabel sizeThatFits:CGSizeMake(rect_screen.size.width-20, 0)].height; [self.titleLabel remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.backView.top).offset(10); make.left.equalTo(self.backView.left).offset(10); make.width.mas_equalTo(rect_screen.size.width-20); make.height.mas_equalTo(titleHeight); }]; } } @end