TUIVoiceReplyQuoteView.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // TUIVoiceReplyQuoteView.m
  3. // TUIChat
  4. //
  5. // Created by harvy on 2021/11/25.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "TUIVoiceReplyQuoteView.h"
  9. #import <TIMCommon/NSString+TUIEmoji.h>
  10. #import <TIMCommon/TIMDefine.h>
  11. #import <TUICore/TUIDarkModel.h>
  12. #import "TUIVoiceReplyQuoteViewData.h"
  13. @implementation TUIVoiceReplyQuoteView
  14. - (instancetype)initWithFrame:(CGRect)frame {
  15. if (self = [super initWithFrame:frame]) {
  16. _iconView = [[UIImageView alloc] init];
  17. _iconView.image = TUIChatCommonBundleImage(@"message_voice_receiver_normal");
  18. [self addSubview:_iconView];
  19. self.textLabel.numberOfLines = 1;
  20. self.textLabel.font = [UIFont systemFontOfSize:10.0];
  21. }
  22. return self;
  23. }
  24. - (void)layoutSubviews {
  25. [super layoutSubviews];
  26. }
  27. - (void)fillWithData:(TUIReplyQuoteViewData *)data {
  28. [super fillWithData:data];
  29. if (![data isKindOfClass:TUIVoiceReplyQuoteViewData.class]) {
  30. return;
  31. }
  32. TUIVoiceReplyQuoteViewData *myData = (TUIVoiceReplyQuoteViewData *)data;
  33. self.iconView.image = myData.icon;
  34. self.textLabel.numberOfLines = 1;
  35. // tell constraints they need updating
  36. [self setNeedsUpdateConstraints];
  37. // update constraints now so we can animate the change
  38. [self updateConstraintsIfNeeded];
  39. [self layoutIfNeeded];
  40. }
  41. + (BOOL)requiresConstraintBasedLayout {
  42. return YES;
  43. }
  44. // this is Apple's recommended place for adding/updating constraints
  45. - (void)updateConstraints {
  46. [super updateConstraints];
  47. [self.iconView mas_remakeConstraints:^(MASConstraintMaker *make) {
  48. make.leading.mas_equalTo(self);
  49. make.top.mas_equalTo(self);
  50. make.width.mas_equalTo(15);
  51. make.height.mas_equalTo(15);
  52. }];
  53. [self.textLabel sizeToFit];
  54. [self.textLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  55. make.leading.mas_equalTo(self.iconView.mas_trailing).mas_offset(3);
  56. make.centerY.mas_equalTo(self.mas_centerY);
  57. make.trailing.mas_equalTo(self.mas_trailing);
  58. make.height.mas_equalTo(self.textLabel.font.lineHeight);
  59. }];
  60. }
  61. @end