// // pushMsgCell.m // ThePaperHD // // Created by liyuan on 15/7/20. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "pushMsgCell.h" @interface pushMsgCell(){ CGFloat titleHeight; } @property(nonatomic, strong) RTLabel *titleLabel; @property(nonatomic, strong) UIImageView *timeIcon; @property(nonatomic, strong) UILabel *timeLabel; @property(nonatomic, strong) UIView *line; @end @implementation pushMsgCell @synthesize data = _data; - (void)awakeFromNib { // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; // self.selectionStyle = UITableViewCellSelectionStyleGray; [self.contentView addSubview:self.titleLabel]; [self.contentView addSubview:self.timeIcon]; [self.contentView addSubview:self.timeLabel]; [self.contentView addSubview:self.line]; UIView *selectView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, CGRectGetWidth(self.bounds)-20, CGRectGetHeight(self.bounds))]; selectView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.selectedBackgroundView = selectView; //5228: 【适配性】6和6P,推送消息页,进入时有一个上提效果,去掉(bug:5228) [self layoutSub]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } return self; } - (void)needrefreshNightMode:(id)sender{ self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.titleLabel.textColor = [UIColor colorWithHexString:TextBlack]; [self.titleLabel setNeedsDisplay]; self.timeLabel.textColor = [UIColor colorWithHexString:TextGray]; self.line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } #pragma mark -- data -(void)setData:(letterBO *)bo{ _data = bo; self.titleLabel.text = _data.summary; self.timeLabel.text = _data.pubTime; titleHeight = returnTextHeightWithRTLabel(self.titleLabel.text, rect_screen.size.width - 30, self.titleLabel.font, 7); [self relayout]; } #pragma mark -- view -(RTLabel *)titleLabel{ if (!_titleLabel) { _titleLabel = [[RTLabel alloc] initWithFrame:CGRectZero]; _titleLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); _titleLabel.textColor = [UIColor colorWithHexString:TextBlack]; // _titleLabel.numberOfLines = 0; // _titleLabel.lineBreakMode = NSLineBreakByWordWrapping; _titleLabel.lineSpacing = 7; _titleLabel.lineBreakMode = RTTextLineBreakModeWordWrapping; _titleLabel.backgroundColor = [UIColor clearColor]; } return _titleLabel; } -(UIImageView *)timeIcon{ if (!_timeIcon) { _timeIcon = [[UIImageView alloc] initWithFrame:CGRectZero]; _timeIcon.image = Image(@"topic/timeImg.png"); } return _timeIcon; } -(UILabel *)timeLabel{ if (!_timeLabel) { _timeLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _timeLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); _timeLabel.textColor = [UIColor colorWithHexString:TextGray]; _timeLabel.lineBreakMode = NSLineBreakByWordWrapping; _timeLabel.backgroundColor = [UIColor clearColor]; } return _timeLabel; } -(UIView *)line{ if (!_line) { _line = [[UIView alloc]initWithFrame:CGRectZero]; _line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _line; } -(void) layoutSub{ [self.titleLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.left).offset(15); make.right.equalTo(self.contentView.right).offset(-15); make.top.equalTo(self.contentView.top).offset(10); make.height.mas_equalTo(25); }]; [self.timeIcon makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.titleLabel.left); make.width.equalTo(@11); make.top.equalTo(self.titleLabel.bottom).offset(10); make.height.equalTo(@11); }]; [self.timeLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.timeIcon.right).offset(5); make.right.equalTo(self.titleLabel.right); make.top.equalTo(self.timeIcon.top); make.height.equalTo(@11); }]; [self.line makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.left).offset(15); make.right.equalTo(self.contentView.right).offset(-15); make.top.equalTo(self.contentView.bottom).offset(-1); make.height.equalTo(1); }]; } -(void)relayout{ // titleHeight = [self.titleLabel sizeThatFits:CGSizeMake(CGRectGetWidth(self.contentView.bounds)-30, 0)].height; titleHeight = returnTextHeightWithRTLabel(self.titleLabel.text, rect_screen.size.width-30, self.titleLabel.font, self.titleLabel.lineSpacing); [self.titleLabel remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.left).offset(15); make.right.equalTo(self.contentView.right).offset(-15); make.top.equalTo(self.contentView.top).offset(10); make.height.mas_equalTo(titleHeight); }]; // [self.selectedBackgroundView makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(self.contentView.left); // make.right.equalTo(self.contentView.right); // make.top.equalTo(self.contentView.top); // make.bottom.equalTo(self.contentView.bottom).offset(-1); // }]; } @end