ios - 在 UIBezierPath 的两侧应用阴影

标签 ios drawing core-graphics uibezierpath

我目前正在屏幕上绘图。我得到流畅的线条,我可以改变我的画的颜色。但我找不到如何对该线应用阴影。

为了绘制它,我使用:

[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/

相关文章:

android - 有什么方法可以在没有 Internet 连接的情况下在 webview 中加载站点?

ios - 如何在 Swift 中使用 NSURLSession downloadTask 顺序下载多个文件

Java Swing/AWT - 使用上下文菜单绘制对象

cocoa-touch - UIImage 到原始 NSData/避免压缩

ios - CSSearchableItemAttributeSet 的 contentDescription 属性不支持换行格式

ios - swift:tableview 返回动画

java - 如何旋转绘图面板中绘制的一系列线条和形状?

c# - 渐变面板在最小化然后恢复时显示红叉

cocoa - 如何在 Mac OSX 中模拟 ctrl+up?

iphone - 如何将本地 jpeg 或 png 图像文件加载到 iPhone 应用程序中?