我正在尝试获取属性字符串的高度。这按预期工作:
[attrString boundingRectWithSize:size
options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine)
context:NULL]
...除非字符串包含表情符号。使用表情符号时,字符串会在标签底部被截断。我需要做什么特别的事情吗?
最佳答案
我知道这是一篇旧文章,但有人可能仍然觉得它有用,您可以转到核心文本,让它为您完成艰苦的工作!
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;
}
关于ios - 带有表情符号的属性字符串 - 适当的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19732585/