Skip to content

Instantly share code, notes, and snippets.

@maninp
Last active August 29, 2015 14:24
Show Gist options
  • Save maninp/ec4ba9584a67072c6ae3 to your computer and use it in GitHub Desktop.
Save maninp/ec4ba9584a67072c6ae3 to your computer and use it in GitHub Desktop.
//
// UILabel+OKASizeCalculator.m
//
// Created by Oliver on 16/01/2014.
// Copyright (c) 2014 Oliver Atkinson. All rights reserved.
//
#import "UILabel+OKASizeCalculator.h"
@implementation UILabel (OKASizeCalculator)
- (CGSize)oka_calculateLabelSizeBoundToSize:(CGSize)boundingSize;
{
UIFont *font = self.font;
NSString *text = self.text;
CGSize size;
if ([text respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) {
size = [text boundingRectWithSize:boundingSize
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{ NSFontAttributeName : font }
context:nil].size;
} else {
size = [text sizeWithFont:font
constrainedToSize:boundingSize
lineBreakMode:self.lineBreakMode];
}
return CGSizeMake(boundingSize.width, size.height);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment