ASMessageListCell.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //
  2. // ASMessageListCell.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/7/4.
  6. //
  7. #import "ASMessageListCell.h"
  8. @interface ASMessageListCell ()
  9. @property (nonatomic,strong) UIView *bgV;
  10. @property (nonatomic,strong) UIStackView *stackV;
  11. @property (nonatomic,strong) UIView *unreadTipV;
  12. @property (nonatomic,strong) UILabel *titleLb;
  13. @property (nonatomic,strong) UIImageView *imgV;
  14. @property (nonatomic,strong) UILabel *desLb;
  15. @property (nonatomic,strong) UILabel *timeLb;
  16. @end
  17. @implementation ASMessageListCell
  18. - (void)awakeFromNib {
  19. [super awakeFromNib];
  20. // Initialization code
  21. }
  22. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  23. [super setSelected:selected animated:animated];
  24. // Configure the view for the selected state
  25. }
  26. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  27. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  28. if (self) {
  29. [self configSubV];
  30. }
  31. return self;
  32. }
  33. - (void)configSubV {
  34. self.selectionStyle = UITableViewCellSelectionStyleNone;
  35. [self.contentView addSubview:self.bgV];
  36. [self.bgV addSubview:self.titleLb];
  37. [self.bgV addSubview:self.unreadTipV];
  38. [self.bgV addSubview:self.stackV];
  39. [self.stackV addArrangedSubview:self.imgV];
  40. [self.stackV addArrangedSubview:self.desLb];
  41. [self.stackV addArrangedSubview:self.timeLb];
  42. [self.bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.top.equalTo(self.contentView).offset(15);
  44. make.bottom.equalTo(self.contentView).offset(-15);
  45. make.left.equalTo(self.contentView).offset(10);
  46. make.right.equalTo(self.contentView).offset(-10);
  47. }];
  48. [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.top.left.equalTo(self.bgV).offset(13);
  50. make.height.equalTo(@20);
  51. make.centerX.equalTo(self.bgV);
  52. }];
  53. [self.unreadTipV mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.width.height.equalTo(@10);
  55. make.centerY.equalTo(self.titleLb);
  56. make.right.equalTo(self.bgV).offset(-20);
  57. }];
  58. [self.stackV mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.top.equalTo(self.titleLb.mas_bottom).offset(13);
  60. make.left.right.equalTo(self.bgV);
  61. make.bottom.equalTo(self.bgV).offset(-20);
  62. }];
  63. [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.width.equalTo(self.bgV);
  65. make.width.equalTo(self.imgV.mas_height).multipliedBy(355/115.0);
  66. }];
  67. [self.timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.height.equalTo(@14);
  69. }];
  70. }
  71. //- (void)setData:(KWMessageListModel *)m {
  72. // self.timeLb.text = m.time;
  73. // self.unreadTipV.hidden = m.isReaded == 1;
  74. // self.titleLb.text = m.title;
  75. // self.desLb.text = m.des;
  76. // if ([m.imgUrl isEmpty]) {
  77. // self.imgV.hidden = true;
  78. // } else {
  79. // self.imgV.hidden = false;
  80. // [self.imgV sd_setImageWithURL:[NSURL URLWithString:m.imgUrl.urlEncode]];
  81. // }
  82. //}
  83. - (void)setMessageModel:(ASMessageModel *)messageModel {
  84. _messageModel = messageModel;
  85. self.timeLb.text = messageModel.time;
  86. self.titleLb.text = AS_String_NotNull(messageModel.title);
  87. self.desLb.text = AS_String_NotNull(messageModel.des);
  88. if (AS_String_valid(messageModel.imgUrl)) {
  89. self.imgV.hidden = NO;
  90. [self.imgV sd_setImageWithURL:[NSURL URLWithString:messageModel.imgUrl] placeholderImage:UIImageDefaultImg_SD];
  91. } else {
  92. self.imgV.hidden = YES;
  93. }
  94. if (messageModel.isReaded) {
  95. self.unreadTipV.hidden = YES;
  96. } else {
  97. self.unreadTipV.hidden = NO;
  98. }
  99. }
  100. - (UIView *)bgV {
  101. if (!_bgV) {
  102. UIView *v = [[UIView alloc] init];
  103. v.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  104. _bgV = v;
  105. }
  106. return _bgV;
  107. }
  108. - (UIView *)unreadTipV {
  109. if (!_unreadTipV) {
  110. UIView *v = [[UIView alloc] init];
  111. v.backgroundColor = [UIColor colorWithHexString:@"#E60013"];
  112. v.layer.cornerRadius = 5;
  113. v.layer.masksToBounds = true;
  114. _unreadTipV = v;
  115. }
  116. return _unreadTipV;
  117. }
  118. -(UIStackView *)stackV {
  119. if (!_stackV) {
  120. UIStackView *stv = [[UIStackView alloc] init];
  121. stv.axis = UILayoutConstraintAxisVertical;
  122. stv.spacing = 10;
  123. stv.alignment = UIStackViewAlignmentFill;
  124. stv.distribution = UIStackViewDistributionFill;
  125. _stackV = stv;
  126. }
  127. return _stackV;
  128. }
  129. - (UILabel *)titleLb {
  130. if (!_titleLb) {
  131. UILabel *lb = [UILabel new];
  132. lb.textColor = [UIColor blackColor];
  133. lb.textAlignment = NSTextAlignmentCenter;
  134. lb.font = [UIFont fontWithName:Rob_Regular size:14];
  135. lb.numberOfLines = 1;
  136. _titleLb = lb;
  137. }
  138. return _titleLb;
  139. }
  140. - (UILabel *)desLb {
  141. if (!_desLb) {
  142. UILabel *lb = [UILabel new];
  143. lb.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
  144. lb.textAlignment = NSTextAlignmentCenter;
  145. lb.font = [UIFont fontWithName:Rob_Regular size:12];
  146. lb.numberOfLines = 1;
  147. _desLb = lb;
  148. }
  149. return _desLb;
  150. }
  151. - (UILabel *)timeLb {
  152. if (!_timeLb) {
  153. UILabel *lb = [UILabel new];
  154. lb.textColor = [[UIColor colorWithHexString:@"#0b0b0b"] colorWithAlphaComponent:1];
  155. lb.textAlignment = NSTextAlignmentCenter;
  156. lb.font = [UIFont fontWithName:Rob_Regular size:12];
  157. lb.numberOfLines = 1;
  158. _timeLb = lb;
  159. }
  160. return _timeLb;
  161. }
  162. - (UIImageView *)imgV {
  163. if (!_imgV) {
  164. UIImageView *v = [[UIImageView alloc] init];
  165. v.contentMode = UIViewContentModeScaleAspectFill;
  166. v.clipsToBounds = true;
  167. _imgV = v;
  168. }
  169. return _imgV;
  170. }
  171. @end