WFCUTextCell.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // TextCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/9/1.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUTextCell.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import "WFCUUtilities.h"
  11. #import "AttributedLabel.h"
  12. #define TEXT_LABEL_TOP_PADDING 3
  13. #define TEXT_LABEL_BUTTOM_PADDING 5
  14. @interface WFCUTextCell () <AttributedLabelDelegate>
  15. @end
  16. @implementation WFCUTextCell
  17. + (CGSize)sizeForClientArea:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
  18. WFCCTextMessageContent *txtContent = (WFCCTextMessageContent *)msgModel.message.content;
  19. CGSize size = [WFCUUtilities getTextDrawingSize:txtContent.text font:[UIFont systemFontOfSize:18] constrainedSize:CGSizeMake(width, 8000)];
  20. size.height += TEXT_LABEL_TOP_PADDING + TEXT_LABEL_BUTTOM_PADDING;
  21. if (size.width < 40) {
  22. size.width += 4;
  23. if (size.width > 40) {
  24. size.width = 40;
  25. } else if (size.width < 24) {
  26. size.width = 24;
  27. }
  28. }
  29. return size;
  30. }
  31. - (void)setModel:(WFCUMessageModel *)model {
  32. [super setModel:model];
  33. WFCCTextMessageContent *txtContent = (WFCCTextMessageContent *)model.message.content;
  34. CGRect frame = self.contentArea.bounds;
  35. self.textLabel.frame = CGRectMake(0, TEXT_LABEL_TOP_PADDING, frame.size.width, frame.size.height - TEXT_LABEL_TOP_PADDING - TEXT_LABEL_BUTTOM_PADDING);
  36. self.textLabel.textAlignment = NSTextAlignmentLeft;
  37. [self.textLabel setText:txtContent.text];
  38. }
  39. - (UILabel *)textLabel {
  40. if (!_textLabel) {
  41. _textLabel = [[AttributedLabel alloc] init];
  42. ((AttributedLabel*)_textLabel).attributedLabelDelegate = self;
  43. _textLabel.numberOfLines = 0;
  44. _textLabel.font = [UIFont systemFontOfSize:18];
  45. _textLabel.userInteractionEnabled = YES;
  46. [self.contentArea addSubview:_textLabel];
  47. }
  48. return _textLabel;
  49. }
  50. #pragma mark - AttributedLabelDelegate
  51. - (void)didSelectUrl:(NSString *)urlString {
  52. [self.delegate didSelectUrl:self withModel:self.model withUrl:urlString];
  53. }
  54. - (void)didSelectPhoneNumber:(NSString *)phoneNumberString {
  55. [self.delegate didSelectPhoneNumber:self withModel:self.model withPhoneNumber:phoneNumberString];
  56. }
  57. @end