我正在尝试获取属性字符串的高度.这正如预期的那样:
[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;
}