@@ -388,6 +388,8 @@ + (YYTextLayout *)layoutWithContainer:(YYTextContainer *)container text:(NSAttri
388
388
NSUInteger *lineRowsIndex = NULL ;
389
389
NSRange visibleRange;
390
390
NSUInteger maximumNumberOfRows = 0 ;
391
+ BOOL constraintSizeIsExtended = NO ;
392
+ CGRect constraintRectBeforeExtended = {0 };
391
393
392
394
text = text.mutableCopy ;
393
395
container = container.copy ;
@@ -399,12 +401,18 @@ + (YYTextLayout *)layoutWithContainer:(YYTextContainer *)container text:(NSAttri
399
401
// CoreText bug when draw joined emoji since iOS 8.3.
400
402
// See -[NSMutableAttributedString setClearColorToJoinedEmoji] for more information.
401
403
static BOOL needFixJoinedEmojiBug = NO ;
404
+ // It may use larger constraint size when create CTFrame with
405
+ // CTFramesetterCreateFrame in iOS 10.
406
+ static BOOL needFixLayoutSizeBug = NO ;
402
407
static dispatch_once_t onceToken;
403
408
dispatch_once (&onceToken, ^{
404
409
double systemVersionDouble = [UIDevice currentDevice ].systemVersion .doubleValue ;
405
410
if (8.3 <= systemVersionDouble && systemVersionDouble < 9 ) {
406
411
needFixJoinedEmojiBug = YES ;
407
412
}
413
+ if (systemVersionDouble >= 10 ) {
414
+ needFixLayoutSizeBug = YES ;
415
+ }
408
416
});
409
417
if (needFixJoinedEmojiBug) {
410
418
[((NSMutableAttributedString *)text) yy_setClearColorToJoinedEmoji ];
@@ -420,6 +428,16 @@ + (YYTextLayout *)layoutWithContainer:(YYTextContainer *)container text:(NSAttri
420
428
if (container.path == nil && container.exclusionPaths .count == 0 ) {
421
429
if (container.size .width <= 0 || container.size .height <= 0 ) goto fail;
422
430
CGRect rect = (CGRect ) {CGPointZero , container.size };
431
+ if (needFixLayoutSizeBug) {
432
+ constraintSizeIsExtended = YES ;
433
+ constraintRectBeforeExtended = UIEdgeInsetsInsetRect (rect, container.insets );
434
+ constraintRectBeforeExtended = CGRectStandardize (constraintRectBeforeExtended);
435
+ if (container.isVerticalForm ) {
436
+ rect.size .width = YYTextContainerMaxSize.width ;
437
+ } else {
438
+ rect.size .height = YYTextContainerMaxSize.height ;
439
+ }
440
+ }
423
441
rect = UIEdgeInsetsInsetRect (rect, container.insets );
424
442
rect = CGRectStandardize (rect);
425
443
cgPathBox = rect;
@@ -511,6 +529,19 @@ + (YYTextLayout *)layoutWithContainer:(YYTextContainer *)container text:(NSAttri
511
529
512
530
YYTextLine *line = [YYTextLine lineWithCTLine: ctLine position: position vertical: isVerticalForm];
513
531
CGRect rect = line.bounds ;
532
+
533
+ if (constraintSizeIsExtended) {
534
+ if (isVerticalForm) {
535
+ if (rect.origin .x + rect.size .width >
536
+ constraintRectBeforeExtended.origin .x +
537
+ constraintRectBeforeExtended.size .width ) break ;
538
+ } else {
539
+ if (rect.origin .y + rect.size .height >
540
+ constraintRectBeforeExtended.origin .y +
541
+ constraintRectBeforeExtended.size .height ) break ;
542
+ }
543
+ }
544
+
514
545
BOOL newRow = YES ;
515
546
if (rowMaySeparated && position.x != lastPosition.x ) {
516
547
if (isVerticalForm) {
0 commit comments