Skip to content

Commit dcd64b2

Browse files
committed
fix text border draw defect when the border out of the view's bounds: #341
1 parent 42bef57 commit dcd64b2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

YYText/Component/YYTextLayout.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,7 +2402,9 @@ static void YYTextDrawBorderRects(CGContextRef context, CGSize size, YYTextBorde
24022402
//-------------------------- single line ------------------------------//
24032403
CGContextSaveGState(context);
24042404
for (UIBezierPath *path in paths) {
2405-
CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
2405+
CGRect bounds = CGRectUnion(path.bounds, (CGRect){CGPointZero, size});
2406+
bounds = CGRectInset(bounds, -2 * border.strokeWidth, -2 * border.strokeWidth);
2407+
CGContextAddRect(context, bounds);
24062408
CGContextAddPath(context, path.CGPath);
24072409
CGContextEOClip(context);
24082410
}
@@ -2443,7 +2445,10 @@ static void YYTextDrawBorderRects(CGContextRef context, CGSize size, YYTextBorde
24432445
rect = CGRectInset(rect, inset, inset);
24442446
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:border.cornerRadius + 2 * border.strokeWidth];
24452447
[path closePath];
2446-
CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
2448+
2449+
CGRect bounds = CGRectUnion(path.bounds, (CGRect){CGPointZero, size});
2450+
bounds = CGRectInset(bounds, -2 * border.strokeWidth, -2 * border.strokeWidth);
2451+
CGContextAddRect(context, bounds);
24472452
CGContextAddPath(context, path.CGPath);
24482453
CGContextEOClip(context);
24492454
}

0 commit comments

Comments
 (0)