我正在尝试为不同的bezierPaths添加单独的颜色,例如
UIGraphicsBeginImageContext(_v_sticker.frame.size);
UIColor *fillColor = [UIColor redColor];
[fillColor setFill];
UIColor *strokeColor = [UIColor blueColor];
[strokeColor setStroke];
p = [UIBezierPath bezierPath];
[p moveToPoint:CGPointMake(60, 10)];
[p addLineToPoint:CGPointMake(110, 60)];
[p addLineToPoint:CGPointMake(60, 110)];
[p addLineToPoint:CGPointMake(10, 60)];
[p closePath];
[p fill];
[p stroke];
fillColor = [UIColor redColor];
[fillColor setFill];
strokeColor = [UIColor blueColor];
[strokeColor setStroke];
p2 = [UIBezierPath bezierPath];
[p2 moveToPoint:CGPointMake(100, 10)];
[p2 addLineToPoint:CGPointMake(150, 60)];
[p2 addLineToPoint:CGPointMake(100, 110)];
[p2 addLineToPoint:CGPointMake(50, 60)];
[p2 closePath];
[p2 fill];
[p2 stroke];
CGMutablePathRef combinedPath = CGPathCreateMutableCopy(p.CGPath);
CGPathAddPath(combinedPath, NULL, p2.CGPath);
combined = [UIBezierPath bezierPathWithCGPath:combinedPath];
CFRelease(combinedPath);
mask = [CAShapeLayer new];
mask.path = combined.CGPath;
[_v_sticker.layer addSublayer:mask];
UIGraphicsEndImageContext();
但除了黑色外,我什么都没得到。我可以给图层赋予颜色但我想直接指定不同的颜色并在单层贝塞尔曲线路径中使用它们
谁能告诉我我在哪里做错了?
答案 0 :(得分:0)
您的代码中存在多个错误:
UIGraphicsGetImageFromCurrentImageContext()
)。 backgroundColor
,strokeColor
)。