|
//
// contentTextCell.m
// ThePaperDemo
//
// Created by scar1900 on 14/11/5.
// Copyright (c) 2014年 scar1900. All rights reserved.
//
#import "contentTextCell.h"
#import "contentTextView.h"
@interface contentTextCell() {
CGFloat contentPadding;
}
//@property(nonatomic, strong)RTLabel *contentLabel;
@property(nonatomic, strong)contentTextView *contentLabel;
@end
@implementation contentTextCell
@synthesize text = _text;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
if (IS_IPHONE_6P) {
contentPadding = 15;
}else if (IS_IPHONE_6) {
contentPadding = 15;
}else {
contentPadding = 10;
}
self.backgroundColor = [UIColor colorWithHexString:ContentDetailBack];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.contentLabel];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
return self;
}
- (void)needrefreshNightMode:(id)sender{
self.backgroundColor = [UIColor colorWithHexString:ContentDetailBack];
self.contentLabel.backgroundColor = [UIColor colorWithHexString:ContentDetailBack];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (contentTextView *)contentLabel {
if (!_contentLabel) {
_contentLabel = [[contentTextView alloc]initWithFrame:CGRectZero];
_contentLabel.backgroundColor = [UIColor colorWithHexString:ContentDetailBack];
[_contentLabel setEditable:NO];
_contentLabel.textAlignment = NSTextAlignmentLeft;
_contentLabel.scrollEnabled = NO;
_contentLabel.showsVerticalScrollIndicator = NO;
_contentLabel.showsHorizontalScrollIndicator = NO;
}
return _contentLabel;
}
- (void)setText:(NSAttributedString *)str {
if (_text != str) {
_text = str;
[self setAutoLayoutSubviews];
}
}
- (void)setAutoLayoutSubviews {
NSInvocationOperation *operation = [[NSInvocationOperation alloc]initWithTarget:self
selector:@selector(readyToReLayout)
object:nil];
[[TPUserDefault instance].globalQueue addOperation:operation];
// CGFloat height = returnTextHeightWithRTLabel(_text, rect_screen.size.width-20, appFont([TPUserDefault instance].contFontSize,NO), 7)+25;
}
- (void)readyToReLayout {
[self performSelectorOnMainThread:@selector(updateCellUI) withObject:nil waitUntilDone:YES];
usleep(1);
}
- (void)updateCellUI {
self.contentLabel.attributeStr = self.text;
[self.contentLabel remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView.top).offset(0);
make.left.equalTo(self.contentView.left).offset(contentPadding-5);
make.width.mas_equalTo(rect_screen.size.width-2*contentPadding+10);
make.height.mas_equalTo(self.textHeight);
}];
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|