I am using TextKit IntroToTextKitDemo2013 sample text in my application.
Here is a sample code link
It dynamically changes the color of the UITextView AttributedString if it is "Alice" or "Rabbit"
When I enter the symbol "#", it works fine, as shown, but when I enter "#" after the emoji icon, it adds a space after the emoji and "#" symbol. I am using iOS 8.3
Here is my code
@property (nonatomic, retain) TKDInteractiveTextColoringTextStorage *textStorage;
-(void)viewDidLoad
{
[super viewDidLoad];
CGRect newTextViewRect = CGRectInset(self.view.bounds, 8., 0.);
self.textStorage = [[TKDInteractiveTextColoringTextStorage alloc] init];
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
NSTextContainer *container = [[NSTextContainer alloc] initWithSize:CGSizeMake(newTextViewRect.size.width, CGFLOAT_MAX)];
container.widthTracksTextView = YES;
[layoutManager addTextContainer:container];
[_textStorage addLayoutManager:layoutManager];
UITextView *newTextView = [[UITextView alloc] initWithFrame:newTextViewRect textContainer:container];
newTextView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
newTextView.scrollEnabled = YES;
newTextView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
[self.view addSubview:newTextView];
self.textView = newTextView;
self.textStorage.tokens = @{ @"Alice" : @{ NSForegroundColorAttributeName : [UIColor redColor] },
@"Rabbit" : @{ NSForegroundColorAttributeName : [UIColor orangeColor] },
TKDDefaultTokenName : @{ NSForegroundColorAttributeName : [UIColor blackColor] } };
}
-(void)setDemo:(TKDDemo *)demo
{
[super setDemo:demo];
(void)[self view];
[_textStorage beginEditing];
[_textStorage setAttributedString:self.demo.attributedText];
[_textStorage endEditing];
}


source
share