fix possible crash of label shrinked (#16456)

This commit is contained in:
子龙山人 2016-08-29 02:23:01 -05:00 committed by minggo
parent df3b33cd59
commit 0b1f61b8ce
1 changed files with 8 additions and 0 deletions

View File

@ -129,6 +129,10 @@ static NSSize _calculateRealSizeForString(NSAttributedString **str, id font, NSS
while (actualSize.size.width > constrainSize.width ||
actualSize.size.height > constrainSize.height) {
fontSize = fontSize - 1;
if (fontSize < 0) {
actualSize = CGRectMake(0, 0, 0, 0);
break;
}
NSMutableAttributedString *mutableString = [[*str mutableCopy] autorelease];
*str = __attributedStringWithFontSize(mutableString, fontSize);
@ -162,6 +166,10 @@ static NSSize _calculateRealSizeForString(NSAttributedString **str, id font, NSS
while (actualSize.size.height > constrainSize.height
||actualSize.size.width > constrainSize.width) {
fontSize = fontSize - 1;
if (fontSize < 0) {
actualSize = CGRectMake(0, 0, 0, 0);
break;
}
NSMutableAttributedString *mutableString = [[*str mutableCopy] autorelease];
*str = __attributedStringWithFontSize(mutableString, fontSize);