[英]Shadow cut off under UIView
I'm trying to add some shadow under a UIView. 我正在尝试在UIView下添加一些阴影。
In drawRect
I created a rounded rectangle bezier path and appended a curved arrow-like bottom part to it (blue stuff) 在
drawRect
我创建了一个圆角的矩形贝塞尔曲线路径,并向其附加了一个弯曲的箭头状底部(蓝色的东西)
Here is the shadow's code : 这是阴影的代码:
...
CGContextSaveGState(context);
CGContextAddPath(context, rectPath.CGPath); // rectPath is the bezier
CGContextSetShadowWithColor(context,shadowSize, 3.0, [[[UIColor blackColor] colorWithAlphaComponent:0.7]CGColor]);
CGContextFillPath(context);
CGContextRestoreGState(context);
...
As you can see, the shadow is cut off at the bottom, that's where the view's frame ends. 如您所见,阴影在底部被切除,这是视图框架的终点。 Can I extend the shadow "outside" the frame ?
我可以将阴影扩展到框架外部吗?
use the CALayer
shadow properties instead of drawing the shadow in drawRect:
使用
CALayer
阴影属性,而不是在drawRect:
中绘制阴影drawRect:
shadowOpacity
shadowRadius
shadowOffset
shadowColor
shadowPath
this can result in some performance issues, which you can reduce by using the shadowPath
property. 这可能会导致一些性能问题,您可以通过使用
shadowPath
属性来减少这些问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.