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)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. [self setDemoData];
  31. }
  32. return self;
  33. }
  34. - (void)configSubV {
  35. self.selectionStyle = UITableViewCellSelectionStyleNone;
  36. [self.contentView addSubview:self.bgV];
  37. [self.bgV addSubview:self.titleLb];
  38. [self.bgV addSubview:self.unreadTipV];
  39. [self.bgV addSubview:self.stackV];
  40. [self.stackV addArrangedSubview:self.imgV];
  41. [self.stackV addArrangedSubview:self.desLb];
  42. [self.stackV addArrangedSubview:self.timeLb];
  43. [self.bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.top.equalTo(self.contentView).offset(15);
  45. make.bottom.equalTo(self.contentView).offset(-15);
  46. make.left.equalTo(self.contentView).offset(10);
  47. make.right.equalTo(self.contentView).offset(-10);
  48. }];
  49. [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.top.left.equalTo(self.bgV).offset(13);
  51. make.height.equalTo(@20);
  52. make.centerX.equalTo(self.bgV);
  53. }];
  54. [self.unreadTipV mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.width.height.equalTo(@10);
  56. make.centerY.equalTo(self.titleLb);
  57. make.right.equalTo(self.bgV).offset(-20);
  58. }];
  59. [self.stackV mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.top.equalTo(self.titleLb.mas_bottom).offset(13);
  61. make.left.right.equalTo(self.bgV);
  62. make.bottom.equalTo(self.bgV).offset(-20);
  63. }];
  64. [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.width.equalTo(self.bgV);
  66. make.width.equalTo(self.imgV.mas_height).multipliedBy(355/115.0);
  67. }];
  68. [self.timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.height.equalTo(@14);
  70. }];
  71. }
  72. //- (void)setData:(KWMessageListModel *)m {
  73. // self.timeLb.text = m.time;
  74. // self.unreadTipV.hidden = m.isReaded == 1;
  75. // self.titleLb.text = m.title;
  76. // self.desLb.text = m.des;
  77. // if ([m.imgUrl isEmpty]) {
  78. // self.imgV.hidden = true;
  79. // } else {
  80. // self.imgV.hidden = false;
  81. // [self.imgV sd_setImageWithURL:[NSURL URLWithString:m.imgUrl.urlEncode]];
  82. // }
  83. //}
  84. - (void)setDemoData {
  85. self.timeLb.text = @"timtimetimetime";
  86. self.unreadTipV.hidden = arc4random()%2 == 1;
  87. self.titleLb.text = @"title title title title title title title";
  88. self.desLb.text = @"content content content content content content content content content content content content content content content content content content content 134";
  89. if (arc4random()%2 == 1) {
  90. self.imgV.hidden = true;
  91. } else {
  92. self.imgV.hidden = false;
  93. self.imgV.image = [UIImage imageNamed:@"vip_bg1"];
  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