|
//
// topicIntroductionCell.m
// ThePaperBase
//
// Created by Huixin on 15/10/16.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "topicIntroductionCell.h"
@interface topicIntroductionCell()
//@property(nonatomic, strong)RTLabel *contentLabel;
@property(nonatomic, strong)UILabel *contentLabel;
@property(nonatomic, strong)NSMutableArray *lineArray;
@end
@implementation topicIntroductionCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self addSubview:self.contentLabel];
[self.contentLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.top).offset(23);
make.left.equalTo(self.left).offset(10);
make.right.equalTo(self.right).offset(-10);
make.height.mas_equalTo(@0);
}];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode) name:REFRESHAFTERNIGHTMODE object:nil];
}
return self;
}
- (void)needrefreshNightMode {
//self.contentLabel.text = self.contentLabel.text;
self.contentLabel.textColor = [UIColor colorWithHexString:TextBlack];
for (UIView *line in self.lineArray) {
line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
//- (RTLabel*)contentLabel {
// if (!_contentLabel) {
// _contentLabel = [[RTLabel alloc] init];
// _contentLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
// _contentLabel.backgroundColor = [UIColor clearColor];
// _contentLabel.textColor = [UIColor colorWithHexString:TextBlack];
// _contentLabel.lineBreakMode = RTTextLineBreakModeWordWrapping;
// _contentLabel.lineSpacing = 10;
// }
// return _contentLabel;
//}
- (UILabel*)contentLabel {
if (!_contentLabel) {
_contentLabel = [UILabel new];
_contentLabel.backgroundColor = [UIColor clearColor];
_contentLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
_contentLabel.textColor = [UIColor colorWithHexString:TextBlack];
_contentLabel.lineBreakMode = NSLineBreakByWordWrapping;
_contentLabel.textAlignment = NSTextAlignmentLeft;
_contentLabel.numberOfLines = 0;
}
return _contentLabel;
}
- (void)addLines:(CGFloat)height {
if (isBlankString(self.contentLabel.text)) {
return;
}
CGFloat lineHeight = self.contentLabel.font.lineHeight;
CGFloat lineAndSpaceHeight = lineHeight + 10;
// int num = height/lineAndSpaceHeight + 1;
int num = (height+10)/lineAndSpaceHeight;
self.lineArray = [NSMutableArray array];
for (int i = 0; i < num; i++) {
UIView *line = [UIView new];
line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
[self addSubview:line];
[self.lineArray addObject:line];
[line makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentLabel.top).offset(i*lineAndSpaceHeight+lineHeight+3);
make.left.equalTo(self.contentLabel.left);
make.right.equalTo(self.contentLabel.right);
make.height.mas_equalTo(@1);
}];
}
}
- (void)setContent:(NSString *)content {
// self.contentLabel.text = content;
// CGFloat height = returnTextHeightWithRTLabel(self.contentLabel.text, rect_screen.size.width-20, self.contentLabel.font, self.contentLabel.lineSpacing);
NSAttributedString *attributedStr = getLineSpaceAttributedString(content, 10, self.contentLabel.font);
self.contentLabel.attributedText = attributedStr;
CGFloat height = [self.contentLabel sizeThatFits:CGSizeMake(rect_screen.size.width-20, CGFLOAT_MAX)].height;
[self.contentLabel remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.top).offset(23);
make.left.equalTo(self.left).offset(10);
make.right.equalTo(self.right).offset(-10);
make.height.mas_equalTo(height);
}];
[self addLines:height];
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|