IOS 8 automatically adds space after emoji icon for color bar in UITextView

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

    //ControllerCode

@property (nonatomic, retain) TKDInteractiveTextColoringTextStorage *textStorage;

-(void)viewDidLoad
{

    [super viewDidLoad];

    // our auto layout views use a design spec that calls for
    // 8 pts on each side except the bottom
    // since we scroll at the top here, only inset the sides

    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];
}

Space added after #

# without space

+4
source share
2 answers

, Font string

[attributedString addAttribute:NSFontAttributeName
                         value:[UIFont fontWithName:@"ProximaNova-Regular" size:16.0]
                         range:NSMakeRange(0, [self.capTextView.text length])];
+1

TextKit . . "SFUIText" iOS 10 "AppleColorEmojiUI" emoji.

: swizzle lineHeight UIFont, . , NSLayoutMangerDelegate.

Neat .

+1

Source: https://habr.com/ru/post/1584427/


All Articles