TUIMergeReplyQuoteView.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // TUIMergeReplyQuoteView.m
  3. // TUIChat
  4. //
  5. // Created by harvy on 2021/11/25.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "TUIMergeReplyQuoteView.h"
  9. #import <TUICore/TUIDarkModel.h>
  10. #import <TUICore/UIView+TUILayout.h>
  11. #import "TUIMergeReplyQuoteViewData.h"
  12. @implementation TUIMergeReplyQuoteView
  13. - (instancetype)initWithFrame:(CGRect)frame {
  14. if (self = [super initWithFrame:frame]) {
  15. _titleLabel = [[UILabel alloc] init];
  16. _titleLabel.text = @"title";
  17. _titleLabel.font = [UIFont systemFontOfSize:10.0];
  18. _titleLabel.textColor = [UIColor d_systemGrayColor];
  19. _titleLabel.numberOfLines = 1;
  20. [self addSubview:_titleLabel];
  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:TUIMergeReplyQuoteViewData.class]) {
  30. return;
  31. }
  32. TUIMergeReplyQuoteViewData *myData = (TUIMergeReplyQuoteViewData *)data;
  33. self.titleLabel.text = myData.title;
  34. // tell constraints they need updating
  35. [self setNeedsUpdateConstraints];
  36. // update constraints now so we can animate the change
  37. [self updateConstraintsIfNeeded];
  38. [self layoutIfNeeded];
  39. }
  40. + (BOOL)requiresConstraintBasedLayout {
  41. return YES;
  42. }
  43. // this is Apple's recommended place for adding/updating constraints
  44. - (void)updateConstraints {
  45. [super updateConstraints];
  46. [self.titleLabel sizeToFit];
  47. [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  48. make.leading.mas_equalTo(self);
  49. make.top.mas_equalTo(self);
  50. make.trailing.mas_equalTo(self.mas_trailing);
  51. make.height.mas_equalTo(self.titleLabel.font.lineHeight);
  52. }];
  53. }
  54. - (void)reset {
  55. [super reset];
  56. self.titleLabel.text = @"";
  57. }
  58. @end