を持ってUIImageView
いUIView
ます。その上に を使って形を描きましたUIBezierPath
。今、私は他の部分を透明にしたいと思っています。私のコードは、
- (void)drawRect:(CGRect)rect
{
self.backgroundColor = [[UIColor clearColor] colorWithAlphaComponent:0.0];
imgV.backgroundColor = [[UIColor clearColor] colorWithAlphaComponent:0.0];
aPath = [UIBezierPath bezierPath];
CGContextRef aRef ;
aRef = UIGraphicsGetCurrentContext();
[[UIColor clearColor] setStroke];
[[UIColor clearColor] setFill];
aPath.lineWidth = 2;
aPath = [UIBezierPath new];
//path is calculated here using addLineToPoint addArcWithCentre methods
[aPath fill];
[aPath stroke];
[self setClippingPath:aPath :imgV];
[[[UIColor clearColor] colorWithAlphaComponent:0.0] setFill];
CGContextFillRect(aRef, rect);
CGContextFillPath(aRef);
self.backgroundColor = [[UIColor clearColor] colorWithAlphaComponent:0.0];
imgV.backgroundColor = [[UIColor clearColor] colorWithAlphaComponent:0.0];
}
- (void) setClippingPath:(UIBezierPath *)clippingPath : (UIImageView *)imgView;
{
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = imgView.frame;
maskLayer.path = [clippingPath CGPath];
maskLayer.backgroundColor = [[[UIColor clearColor] colorWithAlphaComponent:0.0] CGColor];
maskLayer.fillColor = [[UIColor whiteColor] CGColor];
[imgView removeFromSuperview];
imgView.layer.mask = maskLayer;
[self addSubview:imgView];
}
出力は次の画像で確認できます。その画像curの周りの黒い部分が透明になるはず です助けてください。