M80AttributedLabel+NIMKit.m 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //
  2. // M80AttributedLabel+NIMKit
  3. // NIM
  4. //
  5. // Created by chris.
  6. // Copyright (c) 2015 Netease. All rights reserved.
  7. //
  8. #import "M80AttributedLabel+NIMKit.h"
  9. #import "YOUPAINIMInputEmoticonParser.h"
  10. #import "YOUPAINIMInputEmoticonManager.h"
  11. #import "UIImage+NIMKit.h"
  12. @implementation M80AttributedLabel (NIMKit)
  13. - (void)nim_setText:(NSString *)text
  14. {
  15. [self setText:@""];
  16. NSArray *tokens = [[YOUPAINIMInputEmoticonParser currentParser] tokens:text];
  17. for (NIMInputTextToken *token in tokens)
  18. {
  19. if (token.type == NIMInputTokenTypeEmoticon)
  20. {
  21. NIMInputEmoticon *emoticon = [[YOUPAINIMInputEmoticonManager sharedManager] emoticonByTag:token.text];
  22. UIImage *image = [UIImage nim_emoticonInKit:emoticon.filename];
  23. if (image)
  24. {
  25. [self appendImage:image
  26. maxSize:CGSizeMake(18, 18)];
  27. }
  28. }
  29. else
  30. {
  31. NSString *text = token.text;
  32. [self appendText:text];
  33. }
  34. }
  35. }
  36. @end