|
//
// specialContentCell.m
// ThePaperBase
//
// Created by zhousan on 15/7/22.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "specialContentCell.h"
#import "AsyncImageView.h"
#define LABEL_LIMIL_WIDTH rect_screen.size.width - 90
#define IMAGEVIEW_WIDTH 60
@interface specialContentCell () {
CGFloat descHeight;
}
@property (nonatomic,strong) AsyncImageView *liveIcon;
@property (nonatomic,strong) RTLabel *descLabel;
@property (nonatomic,strong) UIView *lineView;
@end
@implementation specialContentCell
- (void)awakeFromNib {
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (nil != self) {
[self addSubview:self.liveIcon];
[self addSubview:self.descLabel];
[self addSubview:self.lineView];
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
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:BackGroundColor];
UIView *selectView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, CGRectGetWidth(self.bounds)-20, CGRectGetHeight(self.bounds))];
selectView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.selectedBackgroundView = selectView;
_descLabel.textColor = [UIColor colorWithHexString:TextBlack];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (AsyncImageView *)liveIcon {
if (_liveIcon == nil) {
_liveIcon = [[AsyncImageView alloc] initWithFrame:CGRectZero];
}
return _liveIcon;
}
- (UIView *)lineView {
if (!_lineView) {
_lineView = [[UIView alloc] initWithFrame:CGRectZero];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _lineView;
}
- (void)setContObjectVO:(listContObjectVO *)contObjectVO {
_contObjectVO = contObjectVO;
self.descLabel.text = contObjectVO.name;
descHeight = self.descLabel.optimumSize.height;
self.liveIcon.imageUrl = contObjectVO.pic;
self.liveIcon.imageId = getImageNameFromURL(contObjectVO.pic);
[self layoutSubViews];
}
- (RTLabel *)descLabel {
if (_descLabel == nil) {
_descLabel = [[RTLabel alloc]initWithFrame:CGRectMake(0, 0, LABEL_LIMIL_WIDTH, 0)];
_descLabel.textAlignment = NSTextAlignmentLeft;
_descLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO);
_descLabel.lineBreakMode = NSLineBreakByWordWrapping;
_descLabel.lineSpacing = 8;
_descLabel.textColor = [UIColor colorWithHexString:TextBlack];
_descLabel.backgroundColor = [UIColor clearColor];
}
return _descLabel;
}
- (void)layoutSubViews {
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
if (readmode == imageMode) {
[self.liveIcon remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.left).offset(10);
make.top.equalTo(self.top).offset(10);
make.height.mas_equalTo(IMAGEVIEW_WIDTH);
make.width.mas_equalTo(IMAGEVIEW_WIDTH);
}];
[self.descLabel remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.liveIcon.right).offset(10);
make.top.equalTo(self.contentView.top).offset(10);
make.height.mas_equalTo(descHeight);
make.width.mas_equalTo(LABEL_LIMIL_WIDTH);
}];
}else {
[self.liveIcon remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.left);
make.top.equalTo(self.top).offset(10);
make.height.mas_equalTo(0);
make.width.mas_equalTo(0);
}];
descHeight = returnTextHeightWithRTLabel(self.descLabel.text, rect_screen.size.width-20, self.descLabel.font, 8);
[self.descLabel remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.liveIcon.right).offset(10);
make.top.equalTo(self.contentView.top).offset(10);
make.height.mas_equalTo(descHeight);
make.width.mas_equalTo(LABEL_LIMIL_WIDTH+70);
}];
}
if ([self.isLast isEqualToString:@"1"]) {
[self.lineView remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView);
make.right.equalTo(self.contentView);
make.top.equalTo(self.bottom).offset(-1);
make.height.mas_equalTo(1);
}];
}else {
[self.lineView remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(10);
make.right.equalTo(self.contentView).offset(-10);
make.top.equalTo(self.bottom).offset(-1);
make.height.mas_equalTo(1);
}];
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|