Created
August 17, 2013 19:08
-
-
Save leapingbytes/6258306 to your computer and use it in GitHub Desktop.
Way to create version proof code in ARC environment. (https://www.leapingbytes.com/blog/version_proofing_your_code_arc_twist)
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
#import <Foundation/Foundation.h> | |
@interface NSString (LBToolbox) | |
- (CGSize) sizeWithWidth: (CGFloat) width andFont: (UIFont*) font; | |
@end |
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
#import "NSString+LBToolbox.h" | |
#ifdef __IPHONE_6_0 | |
@interface NSString (HappyARC) | |
- (CGRect) boundingRectWithSize: (CGSize) size options: (NSStringDrawingOptions) options attributes: (id) attributes context: (id) context; | |
@end | |
#endif | |
@implementation NSString (LBToolbox) | |
- (CGSize) sizeWithWidth: (CGFloat) width andFont: (UIFont*) font { | |
CGSize size = CGSizeMake( width, 2048); | |
CGSize result; | |
if ([self respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) { | |
NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys: font, NSFontAttributeName, nil]; | |
result = [self boundingRectWithSize: size options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context: nil].size; | |
} | |
else { | |
result = [self sizeWithFont: font constrainedToSize: size]; | |
} | |
result.width = width; | |
return result; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment