我想删除以下图像的蓝色部分。如何裁剪绘图的反面? (我相信这是正确的提问方式)
三角形的示例代码:(如果有更好的三角形代码,我也会接受!;)
int lineWidth = 4;
int w = size.size.width;
int h = size.size.height - lineWidth;
CGPoint top = CGPointMake(0+(w/2)+.5, 0);
CGContextClipToRect(ctx, CGRectMake(0, 0, w, h));
CGContextStrokePath(ctx);
CGContextMoveToPoint(ctx, top.x, top.y);
CGContextAddLineToPoint(ctx, top.x + (w/2), top.y + h );
CGContextAddLineToPoint(ctx, top.x - (w/2), top.y + h );
CGContextAddLineToPoint(ctx, top.x, top.y);
CGContextFillPath(ctx);
CGContextSetLineWidth(ctx, lineWidth);
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextMoveToPoint(ctx, top.x, top.y);
CGContextAddLineToPoint(ctx, top.x + (w/2), top.y + h );
CGContextAddLineToPoint(ctx, top.x - (w/2), top.y + h );
CGContextAddLineToPoint(ctx, top.x, top.y);
CGContextStrokePath(ctx);
最佳答案
一个简单的解决方案是使用 UIBazierPath。根据您的意图绘制一条巴齐尔路径。然后调用[path addClip]方法。它将剪掉闭合路径之外的所有内容。
例如,以下代码使您的 View 变成圆角。
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:UIRectCornerAllCorners
cornerRadii:CGSizeMake(6.0, 6.0)];
[path addClip];
关于iphone - 裁剪逆图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13553727/