酷店

KDPMessageTableViewCell.m 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // KDPMessageTableViewCell.m
  3. // KuDianProject
  4. //
  5. // Created by admin on 2019/7/11.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPMessageTableViewCell.h"
  9. #import "KDPNoticeModel.h"
  10. @implementation KDPMessageTableViewCell
  11. {
  12. UILabel *_titleLabel;
  13. UILabel *_timeLabel;
  14. UIView *_grayView;
  15. UIImageView *_iconImageView;
  16. UILabel *_contentLabel;
  17. UIView *_isView;
  18. }
  19. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  20. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  21. [self setContentView];
  22. [self setContentViewConstraints];
  23. }
  24. return self;
  25. }
  26. - (void)setContentView{
  27. self.backgroundColor = [UIColor clearColor];
  28. self.contentView.backgroundColor = [UIColor whiteColor];
  29. self.contentView.layer.cornerRadius = 10;
  30. self.contentView.layer.masksToBounds = YES;
  31. _titleLabel = [[UILabel alloc] init];
  32. _titleLabel.textColor = [UIColor colorWithHex:0x383838];
  33. _titleLabel.font = [UIFont fontWithName:@"PingFangSC-Semibold" size: 15];
  34. [self.contentView addSubview:_titleLabel];
  35. _timeLabel = [[UILabel alloc] init];
  36. _timeLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size: 11];
  37. _timeLabel.textColor = [UIColor colorWithHex:0x9B9B9B];
  38. _timeLabel.textAlignment = NSTextAlignmentRight;
  39. [self.contentView addSubview:_timeLabel];
  40. _grayView = [[UIView alloc] init];
  41. _grayView.backgroundColor = [UIColor colorWithHex:0xF9F9F9];
  42. _grayView.layer.cornerRadius = 4;
  43. _grayView.layer.masksToBounds = YES;
  44. [self.contentView addSubview:_grayView];
  45. _isView =[[UIView alloc]init];
  46. _isView.layer.cornerRadius=3;
  47. _isView.layer.masksToBounds=YES;
  48. _isView.backgroundColor=[UIColor colorWithHex:0xFA2B36];
  49. [self.contentView addSubview:_isView];
  50. _iconImageView = [[UIImageView alloc] init];
  51. [_grayView addSubview:_iconImageView];
  52. _contentLabel = [[UILabel alloc] init];
  53. _contentLabel.numberOfLines = 0;
  54. _contentLabel.textColor = [UIColor colorWithHex:0x333333];
  55. _contentLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size: 14];
  56. [_contentLabel sizeToFit];
  57. [_grayView addSubview:_contentLabel];
  58. }
  59. - (void)setContentViewConstraints{
  60. [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.edges.equalTo(UIEdgeInsetsMake(10, 12, 0, 12));
  62. }];
  63. [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.top.equalTo(self.contentView.mas_top).offset(10);
  65. make.right.equalTo(self.contentView.mas_right).offset(-20);
  66. make.size.equalTo(CGSizeMake(120, 20));
  67. }];
  68. [_isView mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.left.mas_equalTo(self->_timeLabel.mas_right).offset(2);
  70. make.width.height.mas_equalTo(6);
  71. make.centerY.equalTo(self->_timeLabel);
  72. }];
  73. [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.equalTo(self.contentView.mas_left).offset(9);
  75. make.top.equalTo(self.contentView.mas_top).offset(9);
  76. make.height.equalTo(21);
  77. make.right.equalTo(self->_timeLabel.mas_left).offset(-10);
  78. }];
  79. [_grayView mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.left.equalTo(self.contentView.mas_left).offset(10);
  81. make.right.equalTo(self.contentView.mas_right).offset(-10);
  82. make.top.equalTo(self->_titleLabel.mas_bottom).offset(7);
  83. make.bottom.equalTo(self.contentView.mas_bottom).offset(-14);
  84. }];
  85. [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.left.top.bottom.equalTo(self->_grayView);
  87. make.width.equalTo(self->_grayView.mas_height);
  88. }];
  89. [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.left.equalTo(self->_iconImageView.mas_right).offset(11);
  91. make.top.equalTo(self->_grayView.mas_top).offset(6);
  92. make.bottom.equalTo(self->_grayView.mas_bottom).offset(-6);
  93. make.right.equalTo(self->_grayView.mas_right).offset(-6);
  94. }];
  95. }
  96. - (void)configWithViewModel:(id)viewModel indexpath:(NSIndexPath *)indexPath{
  97. KDPNoticeModel *noticeModel = (KDPNoticeModel *)viewModel;
  98. _titleLabel.text = noticeModel.title;
  99. _timeLabel.text = noticeModel.push_at;
  100. [_iconImageView sd_setImageWithURL:[NSURL URLWithString:noticeModel.image_url]placeholderImage:[UIImage imageNamed:placholderImg]];
  101. _contentLabel.text = noticeModel.message;
  102. [self setLineSpace:5.0f withText:noticeModel.message inLabel:_contentLabel];
  103. }
  104. -(void)setLineSpace:(CGFloat)lineSpace withText:(NSString *)text inLabel:(UILabel *)label{
  105. if (!text || !label) {
  106. return;
  107. }
  108. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  109. paragraphStyle.lineSpacing = lineSpace; //设置行间距
  110. paragraphStyle.lineBreakMode = label.lineBreakMode;
  111. paragraphStyle.alignment = label.textAlignment;
  112. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
  113. [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
  114. label.attributedText = attributedString;
  115. }
  116. @end