JXTHomeMessageCell.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // JXTHomeMessageCell.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/4/28.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXTHomeMessageCell.h"
  9. #import "UIView+LK.h"
  10. @interface JXTHomeMessageCell()
  11. @property (nonatomic, strong)UIImageView *IMGHead;
  12. @property (nonatomic, weak)UILabel *contentL;
  13. @property (nonatomic,weak) UIView *line_view;
  14. @end
  15. @implementation JXTHomeMessageCell
  16. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  17. if(self= [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
  18. self.IMGHead = [[UIImageView alloc] init];
  19. self.IMGHead.image = [UIImage imageNamed:@""];
  20. self.IMGHead.layer.cornerRadius=5;
  21. self.IMGHead.layer.masksToBounds=YES;
  22. [self addSubview:self.IMGHead];
  23. [self.IMGHead mas_makeConstraints:^(MASConstraintMaker *make) {
  24. make.centerY.mas_equalTo(self.centerY).mas_offset(0);
  25. make.left.mas_equalTo(15);
  26. make.width.mas_equalTo(52);
  27. make.height.mas_equalTo(52);
  28. }];
  29. UILabel *contentL = [[UILabel alloc]init];
  30. contentL.font=[UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  31. contentL.textColor=[UIColor blackColor];
  32. contentL.textAlignment=NSTextAlignmentLeft;
  33. contentL.numberOfLines=3;
  34. [self addSubview:contentL];
  35. self.contentL=contentL;
  36. [contentL mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.mas_equalTo(self.IMGHead.mas_right).mas_offset(15);
  38. make.centerY.mas_equalTo(self.IMGHead.centerY).mas_offset(0);
  39. }];
  40. UILabel *countTipL = [[UILabel alloc]init];
  41. countTipL.font=[UIFont systemFontOfSize:11 weight:UIFontWeightMedium];
  42. countTipL.textColor=[UIColor whiteColor];
  43. countTipL.backgroundColor=[UIColor redColor];
  44. countTipL.textAlignment=NSTextAlignmentCenter;
  45. countTipL.layer.cornerRadius=9;
  46. countTipL.layer.masksToBounds=YES;
  47. countTipL.hidden=YES;
  48. [self addSubview:countTipL];
  49. self.countTipL=countTipL;
  50. [countTipL mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.right.mas_equalTo(-15);
  52. make.centerY.mas_equalTo(self.IMGHead.centerY).mas_offset(0);
  53. make.width.mas_equalTo(18);
  54. make.height.mas_equalTo(18);
  55. }];
  56. UILabel *guanL = [[UILabel alloc]init];
  57. guanL.font=[UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
  58. guanL.backgroundColor=[UIColor blueColor];
  59. guanL.textColor=[UIColor whiteColor];
  60. guanL.text=@"官方";
  61. guanL.textAlignment=NSTextAlignmentCenter;
  62. guanL.layer.cornerRadius=8;
  63. guanL.layer.masksToBounds=YES;
  64. guanL.hidden=YES;
  65. [self addSubview:guanL];
  66. self.guanL=guanL;
  67. [guanL mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.left.mas_equalTo(self.contentL.mas_right).mas_offset(15);
  69. make.centerY.mas_equalTo(self.contentL.centerY).mas_offset(0);
  70. make.width.mas_equalTo(40);
  71. make.height.mas_equalTo(18);
  72. }];
  73. UIView *line_view = [[UIView alloc]init];
  74. line_view.backgroundColor=kRGBColor(245, 245, 245);
  75. [self addSubview:line_view];
  76. self.line_view=line_view;
  77. [line_view mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.left.mas_equalTo(contentL.mas_left).mas_offset(0);
  79. make.right.mas_equalTo(0);
  80. make.bottom.mas_equalTo(0);
  81. make.height.mas_equalTo(1);
  82. }];
  83. }
  84. return self;
  85. }
  86. +(instancetype)cellWithTableView:(UITableView *)tableView{
  87. static NSString *ID = @"JXTHomeMessageCell";
  88. JXTHomeMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  89. if (cell == nil) {
  90. cell = [[JXTHomeMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
  91. }
  92. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  93. return cell;
  94. }
  95. - (void)createMesageTip:(JXTMessageModel *)teachModel and:(NSString *)countTip and:(NSIndexPath *)indexPath {
  96. _teachModel=teachModel;
  97. self.IMGHead.image=[UIImage imageNamed:teachModel.jx_img];
  98. self.contentL.text=[NSString stringWithFormat:@"%@",teachModel.name];
  99. if ([teachModel.name isEqualToString:@"即信"]) {
  100. [_line_view mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.left.mas_equalTo(_contentL.mas_left).mas_offset(0);
  102. make.right.mas_equalTo(0);
  103. make.bottom.mas_equalTo(0);
  104. make.height.mas_equalTo(1);
  105. }];
  106. }else{
  107. [_line_view mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.left.mas_equalTo(_contentL.mas_left).mas_offset(0);
  109. make.right.mas_equalTo(0);
  110. make.bottom.mas_equalTo(0);
  111. make.height.mas_equalTo(15);
  112. }];
  113. self.line_view.hidden=NO;
  114. }
  115. if ([teachModel.name isEqualToString:@"即信"]) {
  116. self.guanL.hidden=NO;
  117. }else{
  118. self.guanL.hidden=YES;
  119. }
  120. if (indexPath.row==0&& [countTip integerValue]>0&&countTip!=nil) {
  121. self.countTipL.hidden=NO;
  122. self.countTipL.text=[NSString stringWithFormat:@"%@",countTip];
  123. }else{
  124. self.countTipL.hidden=YES;
  125. }
  126. }
  127. -(void)setTeachModel:(JXTMessageModel *)teachModel{
  128. _teachModel=teachModel;
  129. self.IMGHead.image=[UIImage imageNamed:teachModel.jx_img];
  130. self.contentL.text=[NSString stringWithFormat:@"%@",teachModel.name];
  131. // if ([teachModel.name isEqualToString:@"通讯录"]) {
  132. // // self.line_view.hidden=YES;
  133. // }else{
  134. // self.line_view.hidden=NO;
  135. // }
  136. }
  137. -(void)setFrame:(CGRect)frame{
  138. frame.origin.y+=1;
  139. frame.size.height-=1;
  140. [super setFrame:frame];
  141. }
  142. @end