|
//
// msgTopCell.m
// ThePaperBase
//
// Created by YoungLee on 15/11/18.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "msgTopCell.h"
@implementation msgTopCell
@synthesize comment = _comment;
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.backView];
[self.backView addSubview:self.titileLabel];
[self.backView addSubview:self.lineView];
[self.contentView addSubview:self.markLabel];
// 个人主页(我的提问,关注的问题,私信等):个人主页(我的提问,关注的问题,私信等)进入原新闻切换成夜间模式返回,显示异常(bug:6153)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
return self;
}
- (void)needrefreshNightMode:(id)sender{
self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.titileLabel.textColor = [UIColor colorWithHexString:TextLightGray];
self.lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
[self.titileLabel setNeedsDisplay];
}
-(UIView *)backView{
if (!_backView) {
_backView = [UIView new];
_backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
return _backView;
}
- (UILabel*)markLabel {
if (!_markLabel) {
_markLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_markLabel.backgroundColor = [UIColor colorWithHexString:@"0xc32128"];
_markLabel.layer.cornerRadius = 15/2;
_markLabel.clipsToBounds = YES;
_markLabel.textAlignment = NSTextAlignmentCenter;
_markLabel.textColor = [UIColor whiteColor];
_markLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO);
_markLabel.hidden = YES;
}
return _markLabel;
}
-(UILabel *)titileLabel{
if (!_titileLabel) {
_titileLabel = [UILabel new];
_titileLabel.textColor = [UIColor colorWithHexString:TextLightGray];
_titileLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_titileLabel.numberOfLines = 0;
_titileLabel.lineBreakMode = NSLineBreakByCharWrapping;
_titileLabel.backgroundColor = [UIColor clearColor];
}
return _titileLabel;
}
-(UIView *)lineView{
if (!_lineView) {
_lineView = [UIView new];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _lineView;
}
-(void)setComment:(commentObjectVO *)commentBO{
_comment = commentBO;
NSString *topTitle;
if([_comment.objectType intValue] == 3){
topTitle = [NSString stringWithFormat:@"【原话题】%@",_comment.contName];
}else{
topTitle = [NSString stringWithFormat:@"【原新闻】%@",_comment.contName];
}
self.titileLabel.attributedText = getLineSpaceAttributedString(topTitle, 2, appFont(TEXT_SIX_LEVELSIZE, NO));
NSString *newNum = _comment.unNums;
if ([newNum intValue] >0 ) {
if ([newNum intValue] > 9) {
self.markLabel.text = @"9+";
}else{
self.markLabel.text = newNum;
}
self.markLabel.hidden = NO;
}else {
self.markLabel.hidden = YES;
self.markLabel.text = @"0";
}
[self setLayout];
}
-(void) refrshMark{
self.markLabel.hidden = YES;
self.markLabel.text = @"0";
}
-(void)setLayout{
// CGFloat topHeight = heightForAttributeStringWithLabel(self.titileLabel.attributedText, rect_screen.size.width - 40, appFont(TEXT_SIX_LEVELSIZE, NO));
[self.backView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(10);
make.right.equalTo(self.contentView.right).offset(-10);
make.top.equalTo(self.contentView.top).offset(10);
make.bottom.equalTo(self.contentView.bottom);
}];
[self.markLabel makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.backView.right).offset(15/2);
make.width.equalTo(@15);
make.top.equalTo(self.backView.top).offset(-15/2);
make.height.equalTo(@15);
}];
[self.titileLabel makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(5);
make.right.equalTo(self.backView.right).offset(-15);
make.top.equalTo(self.backView.top).offset(5);
make.bottom.equalTo(self.backView.bottom).offset(-6);
}];
[self.lineView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left);
make.right.equalTo(self.backView.right);
make.top.equalTo(self.backView.bottom).offset(-1);
make.height.mas_equalTo(0.5);
}];
}
@end
|