向裁剪后的 UIView 添加阴影
我正在创建一个 iPhone 应用程序。我有这个 UIView,其内容是用路径剪辑的。我想为其添加阴影和/或阴影。最好的方法是什么?对于阴影,我尝试了 CGContextSetShadow() 但它似乎没有效果(也许它在显示的区域之外绘制?)。遮光怎么样?我希望它出现在路径上。最好的方法是什么?是沿着原始剪切路径创建另一个狭窄的剪切条(如果可以有两个剪切路径...)还是需要在另一个CALayer中完成?我什至还不确定那是什么。
I'm creating an iphone application. I have this UIView whose content is clipped with a path. I want to add shading and/or shadow to it. What's the best way to do this? For shadow, I tried CGContextSetShadow() but it doesn't seem to have an effect (perhaps it's drawing outside the shown region?) . How about shading? I want it to appear along the path. What's the best way to go about it? Is it to create another narrow clip strip along the original clipping path (if it's possible to have two clip path... ) Or does this need to be done in another CALayer? I am not even sure what that is yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法向被剪裁或遮罩的图层添加阴影。我执行此操作的方法是使用两个 CALayer,一个用于剪辑的内容,并将其放置在另一个用于未剪辑的阴影的内部。
You can't add shadows to layers which are clipped or masked. The way I would do this is use two CALayers, one for the clipped content and place this inside another for the shadow which isn't clipped.