1234567891011121314151617181920212223242526272829 |
- //
- // Created by zorro on 15/3/7.
- // Copyright (c) 2015 tutuge. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- #import "NSAttributedString+EmojiExtension.h"
- #import "EmojiTextAttachment.h"
- @implementation NSAttributedString (EmojiExtension)
- - (NSString *)getPlainString {
- NSMutableString *plainString = [NSMutableString stringWithString:self.string];
- __block NSUInteger base = 0;
-
- [self enumerateAttribute:NSAttachmentAttributeName inRange:NSMakeRange(0, self.length)
- options:0
- usingBlock:^(id value, NSRange range, BOOL *stop) {
- if (value && [value isKindOfClass:[EmojiTextAttachment class]]) {
- [plainString replaceCharactersInRange:NSMakeRange(range.location + base, range.length)
- withString:((EmojiTextAttachment *) value).emojiTag];
- base += ((EmojiTextAttachment *) value).emojiTag.length - 1;
- }
- }];
-
- return plainString;
- }
- @end
|