AliSoftware/OHAttributedLabel — Issue #47: sizeToFit no longer works
Author: bdittmer
Created: 2011-10-19 18:17:28+00:00
State: open

It appears that changes to sizeThatFits have broken sizeToFit. Unclear if this was intentional or not. Reverting to the old version, below, fixes the issue.

```objective-c
- (CGSize)sizeThatFits:(CGSize)size {
NSMutableAttributedString* attrStrWithLinks = [self attributedTextWithLinks];
if (!attrStrWithLinks) return CGSizeZero;

CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attrStrWithLinks);
CGFloat w = size.width;
CGSize sz = CTFramesetterSuggestFrameSizeWithConstraints(framesetter,CFRangeMake(0,0),NULL,CGSizeMake(w,CGFLOAT_MAX),NULL);
if (framesetter) CFRelease(framesetter);
return CGSizeMake(sz.width,sz.height+1); // take 1pt of margin for security
}
```