我正在画画.我得到流畅的线条,我可以改变图纸的颜色.但我找不到如何将阴影应用于该线.
为了绘制它,我使用:
[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(),则需要更改将bezierpath绘制到视图的方式,以便将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,并通过将其设置为path属性来绘制路径.这将很容易让你添加一个只影响你的路径的阴影.