@@ -2442,24 +2442,31 @@ - (void)tintColorDidChange {
2442
2442
}
2443
2443
2444
2444
- (CGSize)sizeThatFits:(CGSize)size {
2445
- YYTextLayout *textLayout = self.textLayout;
2446
- CGSize currentSize = CGSizePixelCeil(textLayout.textBoundingSize);
2447
- if (_verticalForm) {
2448
- if (currentSize.height == size.height) return currentSize;
2449
- } else {
2450
- if (currentSize.width == size.width) return currentSize;
2445
+ if ((!_verticalForm && size.width == self.bounds.size.width) ||
2446
+ (_verticalForm && size.height == self.bounds.size.height)) {
2447
+ [self _updateIfNeeded];
2448
+ if (!_verticalForm) {
2449
+ if (_containerView.bounds.size.height <= size.height) {
2450
+ return _containerView.bounds.size;
2451
+ }
2452
+ } else {
2453
+ if (_containerView.bounds.size.width <= size.width) {
2454
+ return _containerView.bounds.size;
2455
+ }
2456
+ }
2451
2457
}
2452
2458
2453
- if (_verticalForm) {
2454
- size.width = CGFLOAT_MAX ;
2459
+ if (! _verticalForm) {
2460
+ size.height = YYTextContainerMaxSize.height ;
2455
2461
} else {
2456
- size.height = CGFLOAT_MAX ;
2462
+ size.width = YYTextContainerMaxSize.width ;
2457
2463
}
2458
- YYTextContainer *newContainer = _innerContainer.copy;
2459
- newContainer.size = size;
2460
- YYTextLayout *newLayout = [YYTextLayout layoutWithContainer:newContainer text:textLayout.text];
2461
- CGSize newSize = newLayout.textBoundingSize;
2462
- return CGSizePixelCeil(newSize);
2464
+
2465
+ YYTextContainer *container = [_innerContainer copy];
2466
+ container.size = size;
2467
+
2468
+ YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:_innerText];
2469
+ return layout.textBoundingSize;
2463
2470
}
2464
2471
2465
2472
#pragma mark - Override UIResponder
0 commit comments