My problem is this: I have dynamic content in an iOS app (such as twits - although this is not a twitter app) that include both text and images (mostly icons/emoticons and t
This post may get you going in the right direction for calculating row height:
Retrieve custom prototype cell height from storyboard?
As for performance, have you run Time Profiler to narrow down what is causing lag?
I ran into the same issue und solved it today. I am drawing custom objects between the text with the CTRunDelegateCallbacks
, but boundingRectWithSize:options:context:
did not give me the correct height. (It ignores my custom objects).
Instead I found a lower level API in Core Text, which fulfils all requirements and is totally correct. I created a category for that issue. Have fun using it! :-)
Header file:
#import <Foundation/Foundation.h>
@interface NSAttributedString (boundsForWidth)
- (CGRect)boundsForWidth:(float)width;
@end
Implementation file:
#import "NSAttributedString+boundsForWidth.h"
#import <CoreText/CoreText.h>
@implementation NSAttributedString (boundsForWidth)
- (CGRect)boundsForWidth:(float)width
{
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)self);
CGSize maxSize = CGSizeMake(width, 0);
CGSize size = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0, 0), NULL, maxSize, nil);
CFRelease(framesetter);
return CGRectMake(0, 0, ceilf(size.width), ceilf(size.height));
}
@end