TUIEmojiCell.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // TUIEmojiCell.m
  3. // TUIChat
  4. //
  5. // Created by wyl on 2022/5/26.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "TUIEmojiCell.h"
  9. #import <TIMCommon/NSString+TUIEmoji.h>
  10. #import <TIMCommon/TIMCommonModel.h>
  11. #import "TUIEmojiCellData.h"
  12. #define Avatar_Size 40
  13. @interface TUIEmojiCell ()
  14. @property(nonatomic, strong) UIImageView *avatar;
  15. @property(nonatomic, strong) UILabel *displayName;
  16. @property(nonatomic, strong) UILabel *tapToRemoveLabel;
  17. @property(nonatomic, strong) UIImageView *emoji;
  18. @property(nonatomic, strong) TUIEmojiCellData *data;
  19. @end
  20. @implementation TUIEmojiCell
  21. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  22. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  23. if (self) {
  24. _avatar = [[UIImageView alloc] init];
  25. _avatar.layer.cornerRadius = Avatar_Size / 2.0;
  26. _avatar.layer.masksToBounds = YES;
  27. [self addSubview:_avatar];
  28. _displayName = [[UILabel alloc] init];
  29. _displayName.font = [UIFont boldSystemFontOfSize:kScale390(16)];
  30. _displayName.textColor = [UIColor tui_colorWithHex:@"#666666"];
  31. [self addSubview:_displayName];
  32. _tapToRemoveLabel = [[UILabel alloc] init];
  33. _tapToRemoveLabel.font = [UIFont systemFontOfSize:kScale390(12)];
  34. _tapToRemoveLabel.textColor = [UIColor tui_colorWithHex:@"#666666"];
  35. [self addSubview:_tapToRemoveLabel];
  36. _emoji = [[UIImageView alloc] init];
  37. [self addSubview:_emoji];
  38. }
  39. return self;
  40. }
  41. #pragma mark - UI
  42. - (void)prepareUI {
  43. self.layer.cornerRadius = 12.0f;
  44. self.layer.masksToBounds = YES;
  45. }
  46. - (void)fillWithData:(TUIEmojiCellData *)data {
  47. self.data = data;
  48. [_avatar sd_setImageWithURL:[NSURL URLWithString:data.faceURL] placeholderImage:DefaultAvatarImage];
  49. _displayName.text = data.displayName;
  50. _tapToRemoveLabel.text = @"";
  51. if (data.isCurrentUser) {
  52. _displayName.text = TIMCommonLocalizableString(You);
  53. _tapToRemoveLabel.text = TIMCommonLocalizableString(TUIKitChatTap2Remove);
  54. }
  55. [_emoji setImage:[data.emojiName getEmojiImage]];
  56. }
  57. - (void)layoutSubviews {
  58. [super layoutSubviews];
  59. _avatar.frame = CGRectMake(kScale390(26), (self.contentView.frame.size.height - kScale390(40)) * 0.5, kScale390(40), kScale390(40));
  60. _displayName.frame =
  61. CGRectMake(_avatar.frame.origin.x + _avatar.frame.size.width + kScale390(16), (self.contentView.frame.size.height - kScale390(22)) * 0.5,
  62. self.contentView.frame.size.width - kScale390(60), kScale390(22));
  63. if (self.data.isCurrentUser) {
  64. _displayName.frame = CGRectMake(_avatar.frame.origin.x + _avatar.frame.size.width + kScale390(16), _avatar.frame.origin.y,
  65. self.contentView.frame.size.width - kScale390(60), kScale390(22));
  66. _tapToRemoveLabel.frame = CGRectMake(_avatar.frame.origin.x + _avatar.frame.size.width + kScale390(16),
  67. _displayName.frame.origin.y + _displayName.frame.size.height + kScale390(4),
  68. self.contentView.frame.size.width - kScale390(60), kScale390(12));
  69. }
  70. _emoji.frame =
  71. CGRectMake(self.contentView.frame.size.width - kScale390(32), (self.contentView.frame.size.height - kScale390(16)) * 0.5, kScale390(16), kScale390(16));
  72. }
  73. @end