我想像这个图像一样绘制带有矩形的三角形。
CAShapeLayer *mask = [[CAShapeLayer alloc] init];
mask.frame = imgTest.layer.bounds;
CGFloat width = imgTest.layer.frame.size.width;
CGFloat height = imgTest.layer.frame.size.height;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, nil, 30, 0);
CGPathAddLineToPoint(path, nil, width, 0);
CGPathAddLineToPoint(path, nil, width, height);
CGPathAddLineToPoint(path, nil, 0, height);
CGPathAddLineToPoint(path, nil, 30, 0);
CGPathCloseSubpath(path); mask.path = path;
CGPathRelease(path);
imgTest.layer.mask = mask;
那么如何画出第一张图像形状呢?
答案 0 :(得分:1)
CAShapeLayer *mask = [[CAShapeLayer alloc] init];
mask.frame = imgTest.layer.bounds;
CGFloat width = imgTest.layer.frame.size.width;
CGFloat height = imgTest.layer.frame.size.height;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, nil, 0, 0);
CGPathAddLineToPoint(path, nil, width, 0);
CGPathAddLineToPoint(path, nil, width-30, height);
CGPathAddLineToPoint(path, nil, 0, height);
CGPathAddLineToPoint(path, nil, 0, 0);
CGPathCloseSubpath(path); mask.path = path;
CGPathRelease(path);
imgTest.layer.mask = mask;