I'm trying to get the height of an attributed string. This is working as expected with:
[attrString boundingRectWithSize:size
options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine)
context:NULL]
...unless the string contains emojis. With emojis, the string is cut off at the bottom of the label sized with this. Is there something special I need to do?
I know this is an old post but someone might still find it useful, you could drop to core text and let that do the hard work for you!
static inline CGSize OKASizeWithAttributedString(NSAttributedString *attributedString, CGFloat width) {
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)attributedString);
CGSize targetSize = CGSizeMake(width, CGFLOAT_MAX);
CGSize size = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0, (CFIndex)[attributedString length]), NULL, targetSize, NULL);
CFRelease(framesetter);
return size;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With