123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- //
- // LDMessageListCell.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/5/21.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "LDMessageListCell.h"
- #import "UILabel+ChangeLineSpaceAndWordSpace.h"
- @interface LDMessageListCell ()
- @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 LDMessageListCell
- + (instancetype)cellWithTableView:(UITableView *)tableView {
- static NSString *cellID = nil;
- cellID = NSStringFromClass([self class]);
- LDMessageListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
- if (!cell) {
- cell = [[LDMessageListCell 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:(LDMessageModel *)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
|