ASMessageListCell.m 5.6 KB

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