Last active
August 29, 2015 14:24
-
-
Save maninp/ec4ba9584a67072c6ae3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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