我目前正在屏幕上绘图。我得到流畅的线条,我可以改变我的画的颜色。但我找不到如何对该线应用阴影。
为了绘制它,我使用:
[path strokeWithBlendMode:[path blendMode] alpha:1.0];
我看到我可以使用 CGContextSetShadowWithColor()
但即使如此,我也不确定如何使用它,因为下面是 strokeWithBlendMode
的 CGPath 引用中所说的内容:
This method automatically saves the current graphics state prior to drawing and restores that state when it is done, so you do not have to save the graphics state yourself.
所以我真的不知道该把 CGContextSetShadowWithColor()
或其他任何我可以使用的东西放在哪里。
问候
最佳答案
如果您想使用CGContextSetShadowwithColor()
,那么您需要更改将贝塞尔路径绘制到 View 的方式,以便将CGPath
表示绘制到CGContext
。示例如下:
UIBezierPath *path; // this is your path as before
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextAddPath(context, path.CGPath);
CGContextSetLineWidth(context, 2.0);
CGContextSetBlendMode(context, path.blendMode);
CGContextSetShadowWithColor(context, CGSizeMake(1.0, 1.0), 2.0, [UIColor blackColor].CGColor);
CGContextStrokePath(context);
另一种方法是创建一个新的 CAShapeLayer
并通过将其设置为路径属性来绘制路径。这将很容易让你添加一个只会遮挡你的路径的阴影。
关于ios - 在 UIBezierPath 的两侧应用阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13646507/