> 此文件其实就像swift中扩展。在OC中创建一个文件类型为:Category的文件。
#import <UIKit/UIKit.h>
@interface UILabel (StringFrame)
- (CGSize)boundingRectWithSize:(CGSize)size;
@end
#import "UILabel+StringFrame.h"
@implementation UILabel (StringFrame)
- (CGSize)boundingRectWithSize:(CGSize)size
{
NSDictionary *attribute = @{NSFontAttributeName: self.font};
CGSize retSize = [self.text boundingRectWithSize:size
options:\
NSStringDrawingTruncatesLastVisibleLine |
NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingUsesFontLeading
attributes:attribute
context:nil].size;
return retSize;
}
@end
根据Label中的内容来计算lable 的高度,使它自适应
最新推荐文章于 2022-03-23 15:20:17 发布