2
0

WFCUTextCell.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. + (UIFont *)defaultFont {
  18. // return [UIFont fontWithName:@"PingFangSC-Regular" size:14];
  19. return [UIFont systemFontOfSize:18];
  20. }
  21. + (CGSize)sizeForClientArea:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
  22. WFCCTextMessageContent *txtContent = (WFCCTextMessageContent *)msgModel.message.content;
  23. CGSize size = [WFCUUtilities getTextDrawingSize:txtContent.text font:[WFCUTextCell defaultFont] constrainedSize:CGSizeMake(width, 8000)];
  24. size.height += TEXT_LABEL_TOP_PADDING + TEXT_LABEL_BUTTOM_PADDING;
  25. if (size.width < 40) {
  26. size.width += 4;
  27. if (size.width > 40) {
  28. size.width = 40;
  29. } else if (size.width < 24) {
  30. size.width = 24;
  31. }
  32. }
  33. return size;
  34. }
  35. - (void)setModel:(WFCUMessageModel *)model {
  36. [super setModel:model];
  37. WFCCTextMessageContent *txtContent = (WFCCTextMessageContent *)model.message.content;
  38. CGRect frame = self.contentArea.bounds;
  39. self.textLabel.frame = CGRectMake(0, TEXT_LABEL_TOP_PADDING, frame.size.width, frame.size.height - TEXT_LABEL_TOP_PADDING - TEXT_LABEL_BUTTOM_PADDING);
  40. self.textLabel.textAlignment = NSTextAlignmentLeft;
  41. [self.textLabel setText:txtContent.text];
  42. }
  43. - (UILabel *)textLabel {
  44. if (!_textLabel) {
  45. _textLabel = [[AttributedLabel alloc] init];
  46. ((AttributedLabel*)_textLabel).attributedLabelDelegate = self;
  47. _textLabel.numberOfLines = 0;
  48. _textLabel.font = [WFCUTextCell defaultFont];
  49. _textLabel.userInteractionEnabled = YES;
  50. [self.contentArea addSubview:_textLabel];
  51. }
  52. return _textLabel;
  53. }
  54. #pragma mark - AttributedLabelDelegate
  55. - (void)didSelectUrl:(NSString *)urlString {
  56. [self.delegate didSelectUrl:self withModel:self.model withUrl:urlString];
  57. }
  58. - (void)didSelectPhoneNumber:(NSString *)phoneNumberString {
  59. [self.delegate didSelectPhoneNumber:self withModel:self.model withPhoneNumber:phoneNumberString];
  60. }
  61. @end