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