TXShareLiveCellContentView.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. //
  2. // TXShareLiveCellContentView.m
  3. // TUIChat
  4. //
  5. // Created by 王智 on 2023/8/10.
  6. //
  7. #import "TXShareLiveCellContentView.h"
  8. #import "Masonry.h"
  9. #import "UIImageView+WebCache.h"
  10. #import "TUIDefine.h"
  11. #define TXHexRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
  12. @interface TXShareLiveCellContentView ()
  13. @property (nonatomic, strong) UIImageView *teacherAvatar;
  14. @property (nonatomic, strong) UILabel *descLabel;
  15. @property (nonatomic, strong) UILabel *waitDesc;
  16. @property (nonatomic, strong) UIView *liveView;
  17. @end
  18. @implementation TXShareLiveCellContentView
  19. + (instancetype)shareIntance {
  20. return [[TXShareLiveCellContentView alloc] init];
  21. }
  22. - (instancetype)init {
  23. self = [super init];
  24. if (self) {
  25. [self configUI];
  26. }
  27. return self;
  28. }
  29. - (void)configUI {
  30. self.layer.cornerRadius = 10.0f;
  31. self.backgroundColor = [UIColor whiteColor];
  32. UIView *avatarBg = [[UIView alloc] init];
  33. avatarBg.backgroundColor = TXHexRGB(0xFF4347);
  34. avatarBg.layer.cornerRadius = 22.0f;
  35. [self addSubview:avatarBg];
  36. [avatarBg mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.mas_equalTo(self.mas_left).offset(14);
  38. make.top.mas_equalTo(self.mas_top).offset(11);
  39. make.width.height.mas_equalTo(44);
  40. }];
  41. [avatarBg addSubview:self.teacherAvatar];
  42. [self.teacherAvatar mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.centerX.mas_equalTo(avatarBg.mas_centerX);
  44. make.centerY.mas_equalTo(avatarBg.mas_centerY);
  45. make.width.height.mas_equalTo(42.0);
  46. }];
  47. [self addSubview:self.liveView];
  48. [self.liveView mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.centerX.mas_equalTo(avatarBg.mas_centerX);
  50. make.centerY.mas_equalTo(avatarBg.mas_bottom);
  51. make.width.mas_equalTo(34);
  52. make.height.mas_equalTo(16);
  53. }];
  54. UIView *colorView = [[UIView alloc] init];
  55. colorView.backgroundColor = TXHexRGB(0xFF4347);
  56. colorView.layer.cornerRadius = 6.0f;
  57. [self.liveView addSubview:colorView];
  58. [colorView mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.left.mas_equalTo(self.liveView.mas_left).offset(2);
  60. make.right.mas_equalTo(self.liveView.mas_right).offset(-2);
  61. make.top.mas_equalTo(self.liveView.mas_top).offset(1);
  62. make.bottom.mas_equalTo(self.liveView.mas_bottom).offset(-1);
  63. }];
  64. UILabel *liveLabel = [[UILabel alloc] init];
  65. liveLabel.text = @"直播中";
  66. liveLabel.textColor = TXHexRGB(0xffffff);
  67. liveLabel.font = [UIFont systemFontOfSize:8.0f];
  68. [colorView addSubview:liveLabel];
  69. [liveLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.left.mas_equalTo(colorView.mas_left).offset(2);
  71. make.right.mas_equalTo(colorView.mas_right).offset(-3);
  72. make.top.mas_equalTo(colorView.mas_top).offset(1);
  73. make.bottom.mas_equalTo(colorView.mas_bottom).offset(-1);
  74. }];
  75. UILabel *liveHeadLable = [[UILabel alloc] init];
  76. liveHeadLable.text = @"「正在直播」";
  77. liveHeadLable.font = [UIFont systemFontOfSize:14.0f];
  78. liveHeadLable.textColor = TXHexRGB(0x999999);
  79. [self addSubview:liveHeadLable];
  80. [liveHeadLable mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.left.mas_equalTo(avatarBg.mas_right).offset(7);
  82. make.top.mas_equalTo(avatarBg.mas_top).offset(2);
  83. make.height.mas_equalTo(20);
  84. }];
  85. [self addSubview:self.waitDesc];
  86. [self.waitDesc mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.left.mas_equalTo(liveHeadLable.mas_left);
  88. make.top.mas_equalTo(liveHeadLable.mas_bottom).offset(1);
  89. make.height.mas_equalTo(20);
  90. make.right.mas_equalTo(self.mas_right).offset(-12);
  91. }];
  92. [self addSubview:self.descLabel];
  93. [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.left.mas_equalTo(self.mas_left).offset(12);
  95. make.right.mas_equalTo(self.mas_right).offset(-12);
  96. make.top.mas_equalTo(avatarBg.mas_bottom).offset(8);
  97. }];
  98. UIView *lineView = [[UIView alloc] init];
  99. lineView.backgroundColor = TXHexRGB(0xF2F2F2);
  100. [self addSubview:lineView];
  101. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.left.mas_equalTo(self.mas_left);
  103. make.right.mas_equalTo(self.mas_right);
  104. make.height.mas_equalTo(1);
  105. make.top.mas_equalTo(self.descLabel.mas_bottom).offset(10);
  106. }];
  107. UILabel *enterLabel = [[UILabel alloc] init];
  108. enterLabel.text = @"进入直播间";
  109. enterLabel.font = [UIFont systemFontOfSize:15.0f weight:UIFontWeightMedium];
  110. enterLabel.textColor = TXHexRGB(0xFF4347);
  111. [self addSubview:enterLabel];
  112. [enterLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.centerX.mas_equalTo(self.mas_centerX);
  114. make.height.mas_equalTo(21);
  115. make.top.mas_equalTo(lineView.mas_bottom).offset(7);
  116. }];
  117. }
  118. - (void)configCellWithShareAvatar:(NSString *)avatar teacherName:(NSString *)teacherName liveDesc:(NSString *)desc {
  119. [self.teacherAvatar sd_setImageWithURL:[NSURL URLWithString:[self getUrlEndcodeString:avatar]] placeholderImage:[UIImage imageNamed:@"user_default_avatal"]];
  120. self.waitDesc.text = [NSString stringWithFormat:@"%@在直播间等你哦~",[self returnNoNullStringWithString:teacherName]];
  121. if (![self isEmptyString:desc]) {
  122. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  123. [paragraphStyle setLineSpacing:4];//调整行间距
  124. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:desc attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:14.0f],NSForegroundColorAttributeName:TXHexRGB(0x666666)}];
  125. self.descLabel.attributedText = attr;
  126. }
  127. else {
  128. self.descLabel.text = @"";
  129. }
  130. }
  131. - (NSString *)returnNoNullStringWithString:(NSString *)string {
  132. if (string == nil || string.length == 0) {
  133. return @"";
  134. }
  135. return string;
  136. }
  137. - (NSString *)getUrlEndcodeString:(NSString *)string {
  138. return [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];;
  139. }
  140. - (BOOL)isEmptyString:(NSString *)str {
  141. if (str == nil || str.length == 0) {
  142. return YES;
  143. }
  144. return NO;
  145. }
  146. #pragma mark ------ live view
  147. - (UIImageView *)teacherAvatar {
  148. if (!_teacherAvatar) {
  149. _teacherAvatar = [[UIImageView alloc] init];
  150. _teacherAvatar.contentMode = UIViewContentModeScaleAspectFill;
  151. _teacherAvatar.layer.cornerRadius = 21.0f;
  152. _teacherAvatar.layer.masksToBounds = YES;
  153. }
  154. return _teacherAvatar;
  155. }
  156. - (UIView *)liveView {
  157. if (!_liveView) {
  158. _liveView = [[UIView alloc] init];
  159. _liveView.backgroundColor = [UIColor whiteColor];
  160. _liveView.layer.cornerRadius = 8.0f;
  161. }
  162. return _liveView;
  163. }
  164. - (UILabel *)waitDesc {
  165. if (!_waitDesc) {
  166. _waitDesc = [[UILabel alloc] init];
  167. _waitDesc.textColor = TXHexRGB(0x4A4A4A);
  168. _waitDesc.font = [UIFont systemFontOfSize:14.0f weight:UIFontWeightMedium];
  169. }
  170. return _waitDesc;
  171. }
  172. - (UILabel *)descLabel {
  173. if (!_descLabel) {
  174. _descLabel = [[UILabel alloc] init];
  175. _descLabel.textColor = TXHexRGB(0x666666);
  176. _descLabel.font = [UIFont systemFontOfSize:14.0f weight:UIFontWeightRegular];
  177. _descLabel.numberOfLines = 2;
  178. }
  179. return _descLabel;
  180. }
  181. /*
  182. // Only override drawRect: if you perform custom drawing.
  183. // An empty implementation adversely affects performance during animation.
  184. - (void)drawRect:(CGRect)rect {
  185. // Drawing code
  186. }
  187. */
  188. @end