TXLiveShareCell.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // TXLiveShareCell.m
  3. // TUIChat
  4. //
  5. // Created by 王智 on 2023/8/10.
  6. //
  7. #import "TXLiveShareCell.h"
  8. #import "TXShareLiveCellContentView.h"
  9. #import "Masonry.h"
  10. @interface TXLiveShareCell ()
  11. @property (nonatomic, strong) TXShareLiveCellContentView *liveContentView;
  12. @end
  13. @implementation TXLiveShareCell
  14. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  15. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  16. if (self) {
  17. [self configUI];
  18. }
  19. return self;
  20. }
  21. - (void)configUI {
  22. [self.container addSubview:self.liveContentView];
  23. [self.liveContentView mas_makeConstraints:^(MASConstraintMaker *make) {
  24. make.right.mas_equalTo(self.container.mas_right);
  25. make.top.mas_equalTo(self.container.mas_top);
  26. make.width.mas_equalTo(260);
  27. make.bottom.mas_equalTo(self.container.mas_bottom).offset(-10);
  28. }];
  29. }
  30. - (void)fillWithData:(TXLiveShareMessage *)data {
  31. [super fillWithData:data];
  32. [self.liveContentView configCellWithShareAvatar:data.teacherAvatar teacherName:data.teacherName liveDesc:data.liveDescMessage];
  33. if (data.direction == MsgDirectionIncoming) {
  34. [self.liveContentView mas_remakeConstraints:^(MASConstraintMaker *make) {
  35. make.left.mas_equalTo(self.container.mas_left);
  36. make.top.mas_equalTo(self.container.mas_top);
  37. make.width.mas_equalTo(260);
  38. make.bottom.mas_equalTo(self.container.mas_bottom).offset(-10);
  39. }];
  40. }
  41. else {
  42. [self.liveContentView mas_remakeConstraints:^(MASConstraintMaker *make) {
  43. make.right.mas_equalTo(self.container.mas_right);
  44. make.top.mas_equalTo(self.container.mas_top);
  45. make.width.mas_equalTo(260);
  46. make.bottom.mas_equalTo(self.container.mas_bottom).offset(-10);
  47. }];
  48. }
  49. }
  50. - (TXShareLiveCellContentView *)liveContentView {
  51. if (!_liveContentView) {
  52. _liveContentView = [TXShareLiveCellContentView shareIntance];
  53. }
  54. return _liveContentView;
  55. }
  56. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  57. [super setSelected:selected animated:animated];
  58. // Configure the view for the selected state
  59. }
  60. #pragma mark - TUIMessageCellProtocol
  61. + (CGSize)getContentSize:(TUIMessageCellData *)data {
  62. TXLiveShareMessage *shareMsg = (TXLiveShareMessage *)data;
  63. CGFloat width = ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].bounds.size.width);
  64. if (![self isEmptyString:shareMsg.liveDescMessage]) {
  65. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  66. [paragraphStyle setLineSpacing:4];//调整行间距
  67. CGFloat height = [shareMsg.liveDescMessage boundingRectWithSize:CGSizeMake(260, CGFLOAT_MAX) options:(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:14.0f]} context:nil].size.height + 6;
  68. CGFloat contentHeight = height + 123 + 20;
  69. return CGSizeMake(width, contentHeight);
  70. }
  71. else {
  72. return CGSizeMake(width, 123 + 20);
  73. }
  74. }
  75. + (BOOL)isEmptyString:(NSString *)str {
  76. if (str == nil || str.length == 0) {
  77. return YES;
  78. }
  79. return NO;
  80. }
  81. @end