Emoji characters getting cutoff on many text components in UIKit

Originator:dave11186
Number:rdar://28522327 Date Originated:09/28/2016
Status:Open Resolved:YES
Product:iOS Product Version:10
Classification:UIKit Reproducible:Always
 
The attached project demonstrates the bug in the ". AppleColorEmojiUI" font.

https://github.com/master-nevi/ClippedEmoji

It appears that when an attributed string contains ONLY the .AppleColorEmojiUI font, the height iOS reports for the attributed string (using [NSAttributedString boundingRectWithSize:options:context:]) is too short, and therefore the bounding box generated for the string will clip the bottom.

As soon as a string segment with a taller font is added, done by appending any non-emoji character, the bounding box calculation is corrected.

The other emoji font: AppleColorEmoji does not appear to possess this height issue, hence the workaround to find-and-replace the font attribute. It's also unknown when iOS 10 will decide to use .AppleColorEmojiUI vs AppleColorEmoji when the [NSMutableAttributedString fixAttributesInRange:] "fixes" the emoji characters to use the emoji font.

Steps to Reproduce:
1. Add the string "πŸ˜ŠπŸ˜”β˜ΊοΈπŸ˜" to an NSMutableAttributedString and call [NSMutableAttributedString fixAttributesInRange:] which will fix the emoji character attributes to possess the . AppleColorEmojiUI font. 
2. Then add this attributed string to any UIKit text view.

Expected Results:
Non-clipped emoji.

Actual Results:
The emojis will appear clipped at the bottom.

Version:
iOS 10

Notes:


Configuration:
iOS 10 iPhone 7 Simulator

Comments

Apple has reported to me that this has been fixed in iOS 10.2 beta 3 (Build: 14C5077b). I was able to verify the fix in the iOS 10.2 simulator in Xcode 8.2 beta (8C30a).

Bug acknowledged with no official workaround

Apple has acknowledged this bug. Unfortunately they could not offer an official workaround for the issue at this time.

The unofficial workaround is to find and replace the seemingly broken ".AppleColorEmojiUI" font with the "AppleColorEmoji" font. This isn't ideal as it requires further attributed string processing and knowledge of the internal font name ".AppleColorEmojiUI".


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!