|
//
// specialTopicHeadCell.m
// ThePaperHD
//
// Created by scar1900 on 15/2/13.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "specialTopicHeadCell.h"
#import "AsyncImageView.h"
#define LINETAG 3000
@interface specialTopicHeadCell() {
CGFloat descHeight;
NSInteger numOfLine;
}
//@property(nonatomic, strong)AsyncImageView *headImageView;
@property(nonatomic, strong)RTLabel *headDescLabel;
@end
@implementation specialTopicHeadCell
@synthesize specialBO = _specialBO;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
// [self addSubview:self.headImageView];
[self addSubview:self.headDescLabel];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
return self;
}
- (void)needrefreshNightMode:(id)sender{
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
_headDescLabel.textColor = [UIColor colorWithHexString:TextBlack];
for (NSInteger i =0;i<numOfLine;i++) {
UIView *lineView = [self viewWithTag:LINETAG + i];
lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)setSpecialBO:(specialObjectBO *)specialBO {
_specialBO = specialBO;
// self.headImageView.imageUrl = specialBO.pic;
// self.headImageView.imageId = getImageNameFromURL(specialBO.pic);
NSString *descStr = @"<font color='#00a5eb'>导读 | </font>";
descStr = [descStr stringByAppendingString:specialBO.desc];
descHeight = returnTextHeightWithRTLabel(descStr,
rect_screen.size.width-20,
appFont(TEXT_FIVE_LEVELSIZE, NO),
10);
self.headDescLabel.text = descStr;
CGFloat height = returnTextHeightWithRTLabel(@"高度", rect_screen.size.width-20, appFont(TEXT_FIVE_LEVELSIZE, NO), 10) + 10;
numOfLine = descHeight/height +1;
// NSLog(@"height == %f, lineHeigh == %f",height,appFont(TEXT_FIVE_LEVELSIZE, NO).lineHeight);
[self.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[UIView class]]) {
UIView *subView = obj;
if (subView.tag >= 3000) {
[subView removeFromSuperview];
}
}
}];
for (NSInteger i =0;i<numOfLine;i++) {
UIView *lineView = [[UIView alloc]initWithFrame:CGRectZero];
lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
lineView.tag = LINETAG + i;
[self addSubview:lineView];
}
[self layoutSubViews];
}
- (RTLabel*)headDescLabel {
if (!_headDescLabel) {
_headDescLabel = [[RTLabel alloc]initWithFrame:CGRectZero];
_headDescLabel.textAlignment = RTTextAlignmentLeft;
_headDescLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
_headDescLabel.lineSpacing = 10;
_headDescLabel.textColor = [UIColor colorWithHexString:TextBlack];
}
return _headDescLabel;
}
//- (AsyncImageView*)headImageView {
// if (!_headImageView) {
// _headImageView = [[AsyncImageView alloc]initWithFrame:CGRectZero];
// _headImageView.backgroundColor = [UIColor greenColor];
// }
// return _headImageView;
//}
- (void)layoutSubViews {
CGFloat height = returnTextHeightWithRTLabel(@"高度", rect_screen.size.width-20, appFont(TEXT_FIVE_LEVELSIZE, NO), 10)+10;
NSString *isUseSystem = [TPUserDefault instance].isUseSystemFont;
if ([isUseSystem intValue] == 0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 9) {
for (int i=0; i<numOfLine; i++) {
UIView *lineView = [self viewWithTag:LINETAG+i];
[lineView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(10);
make.top.equalTo(self).offset(15+(height+2)*(i+1)-7);
make.right.equalTo(self).offset(-10);
make.height.mas_equalTo(1);
}];
}
}else {
for (int i=0; i<numOfLine; i++) {
UIView *lineView = [self viewWithTag:LINETAG+i];
[lineView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(10);
make.top.equalTo(self).offset(15+height*(i+1)-9);
make.right.equalTo(self).offset(-10);
make.height.mas_equalTo(1);
}];
}
}
[self.headDescLabel remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.left).offset(10);
make.top.equalTo(self.top).offset(15);
make.height.mas_equalTo(descHeight);
make.width.mas_equalTo(rect_screen.size.width-20);
}];
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|