// // DRMessageListCell.m // YouHuiProject // // Created by 小花 on 2018/5/21. // Copyright © 2018年 kuxuan. All rights reserved. // #import "DRMessageListCell.h" #import "UILabel+ChangeLineSpaceAndWordSpace.h" @interface DRMessageListCell () @property (nonatomic, strong) UIView *bgView; @property (nonatomic, strong) UIView *backgrayView; @property (nonatomic, strong) UILabel *dateLabel; @property (nonatomic, strong) UILabel *title; @property (nonatomic, strong) UILabel *desLabel; @property (nonatomic, strong) UIImageView *arrowIcon; @property(nonatomic,strong)UIView *isView;//是否查看 @end @implementation DRMessageListCell + (instancetype)cellWithTableView:(UITableView *)tableView { static NSString *cellID = nil; cellID = NSStringFromClass([self class]); DRMessageListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { cell = [[DRMessageListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } return cell; } - (void)awakeFromNib { [super 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 YHColorWithHex:0xf4f4f4]; self.selectionStyle = UITableViewCellSelectionStyleNone; [self initSubViews]; } return self; } - (void)initSubViews { [self.contentView addSubview:self.bgView]; [self.bgView addSubview:self.title]; [self.bgView addSubview:self.backgrayView]; [self.backgrayView addSubview:self.desLabel]; [self.bgView addSubview:self.dateLabel]; [self.backgrayView addSubview:self.arrowIcon]; [self.bgView addSubview:self.isView]; [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-10); make.top.mas_equalTo(0); make.height.mas_equalTo(37); }]; [self.isView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.dateLabel.mas_right).offset(2); make.top.mas_equalTo(15.5); make.width.height.mas_equalTo(6); }]; [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.right.mas_equalTo(-10); make.top.mas_equalTo(0); make.bottom.mas_equalTo(-10); }]; [self.title mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.mas_equalTo(10); make.right.mas_equalTo(self.dateLabel.mas_left); make.height.mas_equalTo(37); }]; [self.backgrayView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.right.mas_equalTo(-10); make.top.mas_equalTo(37); make.height.mas_equalTo(60); }]; [self.arrowIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.mas_equalTo(60); make.left.mas_equalTo(0); make.top.mas_equalTo(0); }]; [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.arrowIcon.mas_right).offset(12); make.right.mas_equalTo(-10); make.centerY.mas_equalTo(self.backgrayView.centerY); }]; } - (void)setModel:(DRMessageModel *)model { _model = model; self.title.text = model.title; self.desLabel.text = model.message; if (model.is_view.integerValue == 1) { self.isView.hidden=YES; }else{ self.isView.hidden=NO; } self.dateLabel.text = model.push_at; [self setLineSpace:5.0f withText:self.desLabel.text inLabel:self.desLabel]; [self.arrowIcon sd_setImageWithURL:[NSURL URLWithString:model.image_url]]; } - (void)isRead { self.isView.hidden=YES; } #pragma mark ----- - (UIView *)bgView { if (!_bgView) { _bgView = [[UIView alloc] init]; _bgView.backgroundColor = [UIColor whiteColor]; _bgView.layer.cornerRadius = 10; } return _bgView; } -(UIView *)backgrayView { if (!_backgrayView) { _backgrayView =[[UIView alloc]init]; _backgrayView.backgroundColor =[UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1.0]; _backgrayView.layer.cornerRadius=4; } return _backgrayView; } - (UILabel *)dateLabel { if (!_dateLabel) { _dateLabel = [[UILabel alloc] init]; _dateLabel.textColor = [UIColor YHColorWithHex:0x9B9B9B]; _dateLabel.textAlignment=NSTextAlignmentRight; _dateLabel.font = [UIFont systemFontOfSize:11]; } return _dateLabel; } - (UILabel *)title { if (!_title) { _title = [[UILabel alloc] init]; [_title setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15]]; _title.textColor = [UIColor YHColorWithHex:0x383838]; _title.text = @"热门爆款"; } return _title; } - (UILabel *)desLabel { if (!_desLabel) { _desLabel = [[UILabel alloc] init]; _desLabel.font = [UIFont systemFontOfSize:14]; _desLabel.textColor = [UIColor YHColorWithHex:0x333333]; _desLabel.numberOfLines=0; _desLabel.text = @""; } return _desLabel; } - (UIImageView *)arrowIcon { if (!_arrowIcon) { _arrowIcon = [[UIImageView alloc] init]; _arrowIcon.layer.cornerRadius=4; _arrowIcon.backgroundColor=[UIColor backgroudColor]; } return _arrowIcon; } -(UIView *)isView { if (!_isView) { _isView =[[UIView alloc]init]; _isView.layer.cornerRadius=3; _isView.layer.masksToBounds=YES; _isView.backgroundColor=[UIColor YHColorWithHex:0xFA2B36]; } return _isView; } /** 设置固定行间距文本 @param lineSpace 行间距 @param text 文本内容 @param label 要设置的label */ -(void)setLineSpace:(CGFloat)lineSpace withText:(NSString *)text inLabel:(UILabel *)label{ if (!text || !label) { return; } NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineSpacing = lineSpace; //设置行间距 paragraphStyle.lineBreakMode = label.lineBreakMode; paragraphStyle.alignment = label.textAlignment; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text]; [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])]; label.attributedText = attributedString; } @end