thermogl/TITokenField — pull request #53 by krafttuc (2013-07-26 09:02:25+00:00)
Title: Override sizeThatFits instead of sizeToFit

Hi, I found the following code

``` obj-c
- (void)sizeToFit {

CGFloat accessoryWidth = 0;

if (_accessoryType == TITokenAccessoryTypeDisclosureIndicator){
CGPathRelease(CGPathCreateDisclosureIndicatorPath(CGPointZero, _font.pointSize, kDisclosureThickness, &accessoryWidth));
accessoryWidth += floorf(hTextPadding / 2);
}

CGSize titleSize = [_title sizeWithFont:_font forWidth:(_maxWidth - hTextPadding - accessoryWidth) lineBreakMode:kLineBreakMode];
CGFloat height = floorf(titleSize.height + vTextPadding);

[self setFrame:((CGRect){self.frame.origin, {MAX(floorf(titleSize.width + hTextPadding + accessoryWidth), height - 3), height}})];
[self setNeedsDisplay];
}
```

According to Apple's doc

> Resizes and moves the receiver view so it just encloses its subviews.
> Call this method when you want to resize the current view so that it uses the most appropriate amount of space. Specific UIKit views resize themselves according to their own internal needs. In some cases, if a view does not have a superview, it may size itself to the screen bounds. Thus, if you want a given view to size itself to its parent view, you should add it to the parent view before calling this method.
>
> You **should not override** this method. If you want to change the default sizing information for your view, override the sizeThatFits: instead. That method performs any needed calculations and returns them to this method, which then makes the change.