计算文字尺寸的分类

NSString+Extension.h


#import@interface NSString (Extension)

- (CGSize)textSizewithFont:(UIFont *)font andMaxSize:(CGSize)maxSize;

@end



NSString+Extension.m


#import "NSString+Extension.h"

@implementation NSString (Extension)

- (CGSize)textSizewithFont:(UIFont *)font andMaxSize:(CGSize)maxSize {

NSDictionary * attr = @{NSFontAttributeName : font};

return [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attr context:nil].size;

}

@end


你可能感兴趣的:(计算文字尺寸的分类)