mirror of
https://github.com/leanote/leanote-ios.git
synced 2025-10-15 15:40:44 +00:00
31 lines
918 B
Objective-C
Executable File
31 lines
918 B
Objective-C
Executable File
#import "UILabel+SuggestSize.h"
|
|
|
|
@implementation UILabel (SuggestSize)
|
|
|
|
- (CGSize)suggestedSizeForWidth:(CGFloat)width
|
|
{
|
|
if (self.attributedText) {
|
|
return [self suggestSizeForAttributedString:self.attributedText width:width];
|
|
}
|
|
|
|
return [self suggestSizeForString:self.text width:width];
|
|
}
|
|
|
|
- (CGSize)suggestSizeForAttributedString:(NSAttributedString *)string width:(CGFloat)width
|
|
{
|
|
if (!string) {
|
|
return CGSizeZero;
|
|
}
|
|
return [string boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size;
|
|
}
|
|
|
|
- (CGSize)suggestSizeForString:(NSString *)string width:(CGFloat)width
|
|
{
|
|
if (!string) {
|
|
return CGSizeZero;
|
|
}
|
|
return [self suggestSizeForAttributedString:[[NSAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName: self.font}] width:width];
|
|
}
|
|
|
|
@end
|