|
//
// followCententCell.m
// ThePaperBase
//
// Created by Huixin on 15/9/6.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "followCententCell.h"
#import "AsyncImageView.h"
@interface followCententCell() {
CGFloat titleHeight;
}
@property(nonatomic, strong)AsyncImageView *imgView;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UILabel *bottomLabel;
@property(nonatomic, strong)UIView *lineView;
@end
@implementation followCententCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode) name:REFRESHAFTERNIGHTMODE object:nil];
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;
self.clipsToBounds = YES;
[self.contentView addSubview:self.imgView];
[self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.bottomLabel];
[self.contentView 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 {
[self.imgView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(10);
make.centerY.equalTo(self.contentView.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.right.equalTo(self.contentView.right).offset(-10);
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.contentView.bottom).offset(-10);
make.height.mas_equalTo(@12);
}];
[self.lineView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(10);
make.right.equalTo(self.contentView.right);
make.bottom.equalTo(self.contentView.bottom);
make.height.mas_equalTo(@1);
}];
}
- (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.backgroundColor = [UIColor clearColor];
_titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
_titleLabel.numberOfLines = 0;
}
_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;
}
- (UIView*)lineView {
if (!_lineView) {
_lineView = [[UIView alloc] init];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _lineView;
}
- (void)setListBO:(listContObjectVO *)listInfo {
_listBO = 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.right.equalTo(self.contentView.right).offset(-10);
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.contentView.top).offset(10);
make.left.equalTo(self.contentView.left).offset(10);
make.width.mas_equalTo(rect_screen.size.width-20);
make.height.mas_equalTo(titleHeight);
}];
}
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|