|
//
// topicSearchCell.m
// ThePaperBase
//
// Created by Huixin on 15/8/11.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "topicSearchCell.h"
@interface topicSearchCell ()
@property(nonatomic, strong)UIView *backView;
@property(nonatomic, strong)UILabel *nameLabel;
@property(nonatomic, strong)UIImageView *authImg;
@property(nonatomic, strong)RTLabel *contentLabel;
@property(nonatomic, strong)UILabel *typeLabel;
@property(nonatomic, strong)UILabel *timeLabel;
@property(nonatomic, strong)UIImageView *praiseImg;
@property(nonatomic, strong)UILabel *praiseNumLabel;
@property(nonatomic, strong)UILabel *statusLabel;
@property(nonatomic, strong)UIView *line;
@end
@implementation topicSearchCell
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (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.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
[self.contentView addSubview:self.backView];
[self.backView addSubview:self.nameLabel];
[self.backView addSubview:self.authImg];
[self.backView addSubview:self.contentLabel];
[self.backView addSubview:self.typeLabel];
[self.backView addSubview:self.timeLabel];
[self.backView addSubview:self.praiseImg];
[self.backView addSubview:self.praiseNumLabel];
[self.backView addSubview:self.statusLabel];
[self.backView addSubview:self.line];
[self layoutViews];
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)needrefreshNightMode { //bug5878: 问吧搜索页:问吧搜索一个话题进入其相关新闻,切换成夜间模式,返回至搜索页显示异常
self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.nameLabel.textColor = [UIColor colorWithHexString:TextBlack];
self.contentLabel.textColor = [UIColor colorWithHexString:TextBlack];
self.typeLabel.textColor = [UIColor colorWithHexString:TextGray];
self.timeLabel.textColor = [UIColor colorWithHexString:TextGray];
self.praiseNumLabel.textColor = [UIColor colorWithHexString:TextGray];
self.statusLabel.textColor = [UIColor colorWithHexString:TextGray];
self.line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
self.contentLabel.text = self.contentLabel.text;
}
- (void)layoutViews {
[self.backView makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(10, 10, 0, 10));
}];
[self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.backView.top).offset(10);
make.left.equalTo(self.backView.left).offset(20);
make.height.mas_equalTo(@14);
make.width.mas_equalTo(@0);
}];
[self.authImg makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.nameLabel.right).offset(2);
make.centerY.equalTo(self.nameLabel.centerY);
make.width.and.height.equalTo(@12);
}];
[self.contentLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.nameLabel.bottom).offset(10);
make.left.equalTo(self.backView.left).offset(20);
make.right.equalTo(self.backView.right).offset(-20);
}];
[self.typeLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentLabel.bottom).offset(10);
make.left.equalTo(self.backView.left).offset(20);
make.height.mas_equalTo(@9);
make.width.mas_equalTo(@0);
}];
[self.timeLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.typeLabel.top);
make.left.equalTo(self.typeLabel.right).offset(10);
make.bottom.equalTo(self.typeLabel.bottom);
make.width.mas_equalTo(@0);
}];
[self.praiseImg makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.timeLabel.right).offset(10);
make.centerY.equalTo(self.typeLabel.centerY).offset(-1);
make.width.and.height.mas_equalTo(@10);
}];
[self.praiseNumLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.typeLabel.top);
make.left.equalTo(self.praiseImg.right).offset(5);
make.bottom.equalTo(self.typeLabel.bottom);
make.width.mas_equalTo(@0);
}];
[self.statusLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.typeLabel.top);
make.left.equalTo(self.praiseNumLabel.right).offset(10);
make.bottom.equalTo(self.typeLabel.bottom);
make.right.equalTo(self.contentView.right).offset(-20);
}];
[self.line makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.typeLabel.bottom).offset(10);
make.left.equalTo(self.backView.left);
make.right.equalTo(self.backView.right);
make.bottom.equalTo(self.backView.bottom);
make.height.mas_equalTo(@1);
}];
}
- (void)reLayoutViews {
CGFloat nameWidth = [self.nameLabel sizeThatFits:CGSizeMake(0, 14)].width;
[self.nameLabel remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.backView.top).offset(10);
make.left.equalTo(self.backView.left).offset(20);
make.height.mas_equalTo(@14);
make.width.mas_equalTo(nameWidth);
}];
CGFloat labelWidth1 = [self.typeLabel sizeThatFits:CGSizeMake(0, 9)].width;
[self.typeLabel remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentLabel.bottom).offset(10);
make.left.equalTo(self.backView.left).offset(20);
make.height.mas_equalTo(@9);
make.width.mas_equalTo(labelWidth1);
}];
CGFloat labelWidth2 = [self.timeLabel sizeThatFits:CGSizeMake(0, 9)].width;
[self.timeLabel remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.typeLabel.top);
make.left.equalTo(self.typeLabel.right).offset(10);
make.bottom.equalTo(self.typeLabel.bottom);
make.width.mas_equalTo(labelWidth2);
}];
CGFloat labelWidth3= [self.praiseNumLabel sizeThatFits:CGSizeMake(0, 9)].width;
[self.praiseNumLabel updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.typeLabel.top);
make.left.equalTo(self.praiseImg.right).offset(5);
make.bottom.equalTo(self.typeLabel.bottom);
make.width.mas_equalTo(labelWidth3);
}];
}
- (UIView *)backView {
if (!_backView) {
_backView = [[UIView alloc] init];
_backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
return _backView;
}
- (UILabel*)nameLabel {
if (!_nameLabel) {
_nameLabel = [[UILabel alloc] init];
_nameLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_nameLabel.backgroundColor = [UIColor clearColor];
_nameLabel.textColor = [UIColor colorWithHexString:TextBlack];
}
return _nameLabel;
}
- (UIImageView*)authImg {
if (!_authImg) {
_authImg = [[UIImageView alloc] init];
_authImg.backgroundColor = [UIColor clearColor];
_authImg.image = Image(@"topic/auth.png");
}
return _authImg;
}
- (RTLabel *)contentLabel{
if (!_contentLabel) {
_contentLabel = [[RTLabel alloc] init];
_contentLabel.font = appFont(TEXT_THREE_LEVELSIZE, NO);
_contentLabel.backgroundColor = [UIColor clearColor];
_contentLabel.textColor = [UIColor colorWithHexString:TextBlack];
_contentLabel.lineBreakMode = RTTextLineBreakModeWordWrapping;
_contentLabel.lineSpacing = 7;
}
return _contentLabel;
}
- (UILabel*)typeLabel {
if (!_typeLabel) {
_typeLabel = [[UILabel alloc] init];
_typeLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO);
_typeLabel.backgroundColor = [UIColor clearColor];
_typeLabel.textColor = [UIColor colorWithHexString:TextGray];
}
return _typeLabel;
}
- (UILabel*)timeLabel {
if (!_timeLabel) {
_timeLabel = [[UILabel alloc] init];
_timeLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO);
_timeLabel.backgroundColor = [UIColor clearColor];
_timeLabel.textColor = [UIColor colorWithHexString:TextGray];
}
return _timeLabel;
}
- (UIImageView*)praiseImg {
if (!_praiseImg) {
_praiseImg = [[UIImageView alloc] init];
_praiseImg.backgroundColor = [UIColor clearColor];
_praiseImg.image = Image(@"topic/praise.png");
}
return _praiseImg;
}
- (UILabel*)praiseNumLabel {
if (!_praiseNumLabel) {
_praiseNumLabel = [[UILabel alloc] init];
_praiseNumLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO);
_praiseNumLabel.backgroundColor = [UIColor clearColor];
_praiseNumLabel.textColor = [UIColor colorWithHexString:TextGray];
}
return _praiseNumLabel;
}
- (UILabel*)statusLabel {
if (!_statusLabel) {
_statusLabel = [[UILabel alloc] init];
_statusLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO);
_statusLabel.backgroundColor = [UIColor clearColor];
_statusLabel.textColor = [UIColor colorWithHexString:TextGray];
}
return _statusLabel;
}
- (UIView *)line {
if (!_line) {
_line = [[UIView alloc] init];
_line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _line;
}
- (void)setData:(TopicInfoBO*)topic key:(NSString *)key {
userBO *user = setJsonDicToDataModel(topic.userInfo, [userBO class]);
NSString *username = user.sname;
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:username];
NSRange range = [username rangeOfString:key];
while (range.location != NSNotFound) {
[attributeString setAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:BLUECOLOR]} range:range];
NSInteger location = range.location+[key length];
NSRange searchRange = NSMakeRange(location, [username length]-location);
range = [username rangeOfString:key options:0 range:searchRange];
}
self.nameLabel.attributedText = attributeString;//bug5144: 【适配性】ios9,系统字体,话题搜索,不显示题主昵称
if ([user.isAuth intValue]) {
self.authImg.hidden = NO;
}
else
self.authImg.hidden = YES;
NSString *content = topic.title;
if ([content isMatchedByRegex:key]){
content = [content stringByReplacingOccurrencesOfString:key withString:[NSString stringWithFormat:@"<font color='#00a5eb'>%@</font><N>", key]];
}
self.contentLabel.text = content;
self.typeLabel.text = topic.categoryName;
self.timeLabel.text = topic.publishTime;
self.praiseNumLabel.text = topic.praiseTimes;
switch ([topic.status intValue]) {
case 0:
self.statusLabel.text = @"提问已提交待审核";
break;
case 1:
if ([topic.replyedNum intValue] <= 0) {
self.statusLabel.text = @"提问征集中...";
}
else {
self.statusLabel.text = @"进行中...";
}
break;
case 2:
self.statusLabel.text = @"提问审核不通过";
break;
case 3:
self.statusLabel.text = @"已关闭提问";
break;
default:
break;
}
[self reLayoutViews];
}
@end
|