《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRMessageListCell.m 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. //
  2. // DRMessageListCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/21.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRMessageListCell.h"
  9. #import "UILabel+ChangeLineSpaceAndWordSpace.h"
  10. @interface DRMessageListCell ()
  11. @property (nonatomic, strong) UIView *bgView;
  12. @property (nonatomic, strong) UIView *backgrayView;
  13. @property (nonatomic, strong) UILabel *dateLabel;
  14. @property (nonatomic, strong) UILabel *title;
  15. @property (nonatomic, strong) UILabel *desLabel;
  16. @property (nonatomic, strong) UIImageView *arrowIcon;
  17. @property(nonatomic,strong)UIView *isView;//是否查看
  18. @end
  19. @implementation DRMessageListCell
  20. + (instancetype)cellWithTableView:(UITableView *)tableView {
  21. static NSString *cellID = nil;
  22. cellID = NSStringFromClass([self class]);
  23. DRMessageListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  24. if (!cell) {
  25. cell = [[DRMessageListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  26. }
  27. return cell;
  28. }
  29. - (void)awakeFromNib {
  30. [super awakeFromNib];
  31. // Initialization code
  32. }
  33. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  34. [super setSelected:selected animated:animated];
  35. // Configure the view for the selected state
  36. }
  37. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  38. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  39. if (self) {
  40. self.backgroundColor = [UIColor YHColorWithHex:0xf4f4f4];
  41. self.selectionStyle = UITableViewCellSelectionStyleNone;
  42. [self initSubViews];
  43. }
  44. return self;
  45. }
  46. - (void)initSubViews {
  47. [self.contentView addSubview:self.bgView];
  48. [self.bgView addSubview:self.title];
  49. [self.bgView addSubview:self.backgrayView];
  50. [self.backgrayView addSubview:self.desLabel];
  51. [self.bgView addSubview:self.dateLabel];
  52. [self.backgrayView addSubview:self.arrowIcon];
  53. [self.bgView addSubview:self.isView];
  54. [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.right.mas_equalTo(-10);
  56. make.top.mas_equalTo(0);
  57. make.height.mas_equalTo(37);
  58. }];
  59. [self.isView mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.left.mas_equalTo(self.dateLabel.mas_right).offset(2);
  61. make.top.mas_equalTo(15.5);
  62. make.width.height.mas_equalTo(6);
  63. }];
  64. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.mas_equalTo(10);
  66. make.right.mas_equalTo(-10);
  67. make.top.mas_equalTo(0);
  68. make.bottom.mas_equalTo(-10);
  69. }];
  70. [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.top.mas_equalTo(0);
  72. make.left.mas_equalTo(10);
  73. make.right.mas_equalTo(self.dateLabel.mas_left);
  74. make.height.mas_equalTo(37);
  75. }];
  76. [self.backgrayView mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.left.mas_equalTo(10);
  78. make.right.mas_equalTo(-10);
  79. make.top.mas_equalTo(37);
  80. make.height.mas_equalTo(60);
  81. }];
  82. [self.arrowIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.width.height.mas_equalTo(60);
  84. make.left.mas_equalTo(0);
  85. make.top.mas_equalTo(0);
  86. }];
  87. [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.mas_equalTo(self.arrowIcon.mas_right).offset(12);
  89. make.right.mas_equalTo(-10);
  90. make.centerY.mas_equalTo(self.backgrayView.centerY);
  91. }];
  92. }
  93. - (void)setModel:(DRMessageModel *)model {
  94. _model = model;
  95. self.title.text = model.title;
  96. self.desLabel.text = model.message;
  97. if (model.is_view.integerValue == 1) {
  98. self.isView.hidden=YES;
  99. }else{
  100. self.isView.hidden=NO;
  101. }
  102. self.dateLabel.text = model.push_at;
  103. [self setLineSpace:5.0f withText:self.desLabel.text inLabel:self.desLabel];
  104. [self.arrowIcon sd_setImageWithURL:[NSURL URLWithString:model.image_url]];
  105. }
  106. - (void)isRead {
  107. self.isView.hidden=YES;
  108. }
  109. #pragma mark -----
  110. - (UIView *)bgView {
  111. if (!_bgView) {
  112. _bgView = [[UIView alloc] init];
  113. _bgView.backgroundColor = [UIColor whiteColor];
  114. _bgView.layer.cornerRadius = 10;
  115. }
  116. return _bgView;
  117. }
  118. -(UIView *)backgrayView
  119. {
  120. if (!_backgrayView) {
  121. _backgrayView =[[UIView alloc]init];
  122. _backgrayView.backgroundColor =[UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1.0];
  123. _backgrayView.layer.cornerRadius=4;
  124. }
  125. return _backgrayView;
  126. }
  127. - (UILabel *)dateLabel {
  128. if (!_dateLabel) {
  129. _dateLabel = [[UILabel alloc] init];
  130. _dateLabel.textColor = [UIColor YHColorWithHex:0x9B9B9B];
  131. _dateLabel.textAlignment=NSTextAlignmentRight;
  132. _dateLabel.font = [UIFont systemFontOfSize:11];
  133. }
  134. return _dateLabel;
  135. }
  136. - (UILabel *)title {
  137. if (!_title) {
  138. _title = [[UILabel alloc] init];
  139. [_title setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15]];
  140. _title.textColor = [UIColor YHColorWithHex:0x383838];
  141. _title.text = @"热门爆款";
  142. }
  143. return _title;
  144. }
  145. - (UILabel *)desLabel {
  146. if (!_desLabel) {
  147. _desLabel = [[UILabel alloc] init];
  148. _desLabel.font = [UIFont systemFontOfSize:14];
  149. _desLabel.textColor = [UIColor YHColorWithHex:0x333333];
  150. _desLabel.numberOfLines=0;
  151. _desLabel.text = @"";
  152. }
  153. return _desLabel;
  154. }
  155. - (UIImageView *)arrowIcon {
  156. if (!_arrowIcon) {
  157. _arrowIcon = [[UIImageView alloc] init];
  158. _arrowIcon.layer.cornerRadius=4;
  159. _arrowIcon.backgroundColor=[UIColor backgroudColor];
  160. }
  161. return _arrowIcon;
  162. }
  163. -(UIView *)isView
  164. {
  165. if (!_isView) {
  166. _isView =[[UIView alloc]init];
  167. _isView.layer.cornerRadius=3;
  168. _isView.layer.masksToBounds=YES;
  169. _isView.backgroundColor=[UIColor YHColorWithHex:0xFA2B36];
  170. }
  171. return _isView;
  172. }
  173. /**
  174. 设置固定行间距文本
  175. @param lineSpace 行间距
  176. @param text 文本内容
  177. @param label 要设置的label
  178. */
  179. -(void)setLineSpace:(CGFloat)lineSpace withText:(NSString *)text inLabel:(UILabel *)label{
  180. if (!text || !label) {
  181. return;
  182. }
  183. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  184. paragraphStyle.lineSpacing = lineSpace; //设置行间距
  185. paragraphStyle.lineBreakMode = label.lineBreakMode;
  186. paragraphStyle.alignment = label.textAlignment;
  187. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
  188. [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
  189. label.attributedText = attributedString;
  190. }
  191. @end