Browse Source

fix text border draw defect when the border out of the view's bounds: #341

ibireme 9 years ago
parent
commit
dcd64b27e9
1 changed files with 7 additions and 2 deletions
  1. 7 2
      YYText/Component/YYTextLayout.m

+ 7 - 2
YYText/Component/YYTextLayout.m

@@ -2402,7 +2402,9 @@ static void YYTextDrawBorderRects(CGContextRef context, CGSize size, YYTextBorde
         //-------------------------- single line ------------------------------//
         //-------------------------- single line ------------------------------//
         CGContextSaveGState(context);
         CGContextSaveGState(context);
         for (UIBezierPath *path in paths) {
         for (UIBezierPath *path in paths) {
-            CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
+            CGRect bounds = CGRectUnion(path.bounds, (CGRect){CGPointZero, size});
+            bounds = CGRectInset(bounds, -2 * border.strokeWidth, -2 * border.strokeWidth);
+            CGContextAddRect(context, bounds);
             CGContextAddPath(context, path.CGPath);
             CGContextAddPath(context, path.CGPath);
             CGContextEOClip(context);
             CGContextEOClip(context);
         }
         }
@@ -2443,7 +2445,10 @@ static void YYTextDrawBorderRects(CGContextRef context, CGSize size, YYTextBorde
                 rect = CGRectInset(rect, inset, inset);
                 rect = CGRectInset(rect, inset, inset);
                 UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:border.cornerRadius + 2 * border.strokeWidth];
                 UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:border.cornerRadius + 2 * border.strokeWidth];
                 [path closePath];
                 [path closePath];
-                CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
+                
+                CGRect bounds = CGRectUnion(path.bounds, (CGRect){CGPointZero, size});
+                bounds = CGRectInset(bounds, -2 * border.strokeWidth, -2 * border.strokeWidth);
+                CGContextAddRect(context, bounds);
                 CGContextAddPath(context, path.CGPath);
                 CGContextAddPath(context, path.CGPath);
                 CGContextEOClip(context);
                 CGContextEOClip(context);
             }
             }