Reputation: 19802
I found some strange behviour of UILabel with attributed text and Emoji icons. Have no idea how to fix it.
Here is my code I'm doing every time text changes on textfield.
NSLog(@"bef %@", self.textView.attributedText);
self.textView.attributedText = [[NSMutableAttributedString alloc] initWithString:self.textView.text];
NSLog(@"after %@", self.textView.attributedText);
output is:
bef qwe{
NSFont = "<UICTFont: 0x7fc88b0e23d0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
NSOriginalFont = "<UICTFont: 0x7fc88b0e23d0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
}😄{
NSFont = "<UICTFont: 0x7fc88a4d6aa0> font-family: \"Apple Color Emoji\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
NSOriginalFont = "<UICTFont: 0x7fc88b0e23d0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
}1{
NSFont = "<UICTFont: 0x7fc88b0e23d0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
}
2014-11-06 15:49:04.256 Inbot Dev[31162:506070] after qwe{
NSFont = "<UICTFont: 0x7fc88b0e23d0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
NSOriginalFont = "<UICTFont: 0x7fc88b0e23d0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
}😄1{
NSFont = "<UICTFont: 0x7fc88a4d6aa0> font-family: \"Apple Color Emoji\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
NSOriginalFont = "<UICTFont: 0x7fc88b0e23d0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
}
Actual problem is that "1" after Emoji is getting inside Emoji block, but it shouldn't. I'm doing some custom decoration on NSMutableAttributedString, that's just an example of problem that I narrowed down.
More interesting thing is that only happens for numbers, if I put letter after Emoji is okey...
Seems like while setting attributedText it is doing some extra stuff for Emoji. Anyone got this problem before ?
Upvotes: 1
Views: 1036
Reputation: 19802
Actually problem was solved by setting a default font for whole text while creating NSMutableAttributedString.
Seems problem occurs only when using Helvetica fallback
What I'm doing is:
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.alignment = style == kDecorateStringStyleDark ? NSTextAlignmentLeft : NSTextAlignmentRight;
NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:sourceString attributes:@{ NSParagraphStyleAttributeName : paragraphStyle }];
//this part below fixed the problem (by default it was using Helvetica)
[attString addAttribute:NSFontAttributeName value:FONT(FONT_MEDIUM, 14.0f) range:NSMakeRange(0, sourceString.length)];
//after that you can decorate parts of text as you want to
Upvotes: 1