输入字符串 自动计算label 的高度

NSObject+bounding.h

import

import

@interface NSObject (bounding)
-(CGRect)contentRectWithString:(NSString * )string labelScreenWith:(CGFloat)screenwith AndStringFont:(int)floatnumber;
@end

NSObject+bounding.m里面写

import "NSObject+bounding.h"

@implementation NSObject (bounding)

-(CGRect)contentRectWithString:(NSString *)string labelScreenWith:(CGFloat)screenwith AndStringFont:(int)floatnumber
{
CGRect tmpRect = [string boundingRectWithSize:CGSizeMake(screenwith, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:SetFont(floatnumber),NSFontAttributeName, nil] context:nil];

return tmpRect;

}

@end

你可能感兴趣的:(输入字符串 自动计算label 的高度)