저는 다음 코드를 사용하여 Trinagle 모양을 그렸습니다. 나는이 모양에 그림자를 적용하고 싶습니다. Bezierpath를 사용하여 그려 왔습니다.은 shibow에 uibiezierpath를 보여줍니다.
CGContextRef context = UIGraphicsGetCurrentContext();
//creating a new nsshadow
NSShadow* shadow = [[NSShadow alloc] init];
[shadow setShadowColor: UIColor.blackColor];
[shadow setShadowOffset: CGSizeMake(3.1, 3.1)];
[shadow setShadowBlurRadius: 5];
//view to add a bezier path
UIView *triangleView = [[UIView alloc] initWithFrame:CGRectMake(67.0f,33.4f, 40.0f ,20.0f)];
// code for drawing a trinagular shape
UIBezierPath* trianglePath = [UIBezierPath bezierPath];
[trianglePath moveToPoint:CGPointMake(0, 0)];
[trianglePath addQuadCurveToPoint:CGPointMake(7.0f, 3.0f) controlPoint:CGPointMake(4.0f, 0.0f)];
[trianglePath addLineToPoint:CGPointMake(17.0f,15.0f)];
[trianglePath addQuadCurveToPoint:CGPointMake(23.0f,15.0f) controlPoint:CGPointMake(20.0f, 20.0f)];
[trianglePath addLineToPoint:CGPointMake(33.0f, 3.0f)];
[trianglePath addQuadCurveToPoint:CGPointMake(40.0, 0.0f) controlPoint:CGPointMake(36.5f, 0.0f)];
[trianglePath addLineToPoint:CGPointMake(0.0f, 0.0f)];
CGContextAddPath(context, trianglePath.CGPath);
CGContextSaveGState(context);
CGContextSetShadowWithColor(context, shadow.shadowOffset, shadow.shadowBlurRadius, [shadow.shadowColor CGColor]);
[UIColor.redColor setFill];
[trianglePath fill];
CGContextRestoreGState(context);
[UIColor.blackColor setStroke];
trianglePath.lineWidth = 1;
[trianglePath stroke];
CGContextFillPath(context);
//CAShapeLayer to set the bezier path
CAShapeLayer *triangleMaskLayer = [CAShapeLayer layer];
[triangleMaskLayer setPath:trianglePath.CGPath];
triangleMaskLayer.lineWidth = 0.1f;
triangleMaskLayer.fillColor = [[UIColor whiteColor] CGColor];
[triangleView.layer addSublayer:triangleMaskLayer];
이 uibezier 경로에 그림자를 설정하고 싶습니까? 나는 어떤 방법을 사용해 보았지만 어떤 것이 잘못되었는지 알아 내지 못했습니까? 아래와 같이 CAShapeLayer
에 그림자 속성을 설정하여