在 UIView 中创建内部阴影
我想在 iPad 上的 UIView
上创建一个内部阴影,如下所示:
这UIView
可以改变大小,所以我不能使用简单的图像来创建这种阴影。
我已经使用 setShadow
等进行了测试,但它只是创建了一个投影。
知道如何创建这种阴影吗?
I would like create an inner shadow on my UIView
on iPad like that :
This UIView
could change size so I can't use a simple image to create this kind of shadow.
I have tested with setShadow
etc., but it's only a dropshadow that is created.
Any idea how to create this kind of shadow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可能会发现它很有用,我为此创建了一个 UIView 类别
https://github.com/Seitk/UIView-Shadow-Maker
You may find it useful, I made an UIView Category for that
https://github.com/Seitk/UIView-Shadow-Maker
将阴影创建为特定大小的透明层,然后创建可拉伸图像,如下所示:
然后,您可以将其作为图像放入 UIImageView 中,并使用 contentMode 缩放来适应,它将按照您想要的方式工作。
假设您的视图名为“myView”。您可以像这样添加阴影:
如果您愿意,您也可以在界面生成器中完成大部分操作,只要您在代码中创建可拉伸图像本身。
Create the shadow as a transparent layer at a particular size, then create a stretchable image, like this:
You can then put that as the image in a UIImageView with contentMode scale to fit and it will work the way you want.
Lets say your view is called "myView". You can add the shadow like this:
You can also do most of this in interface builder if you prefer, as long as you create the stretchable image itself in code.
这个问题已经在 SO 中得到了部分
回答使用变量,直到它们适合您的阴影样式。
更新
相反,您可以在现有视图之上的较小居中视图上绘制外部阴影。
This question was already partially answered in SO
Play around with the variables until they suit your shadow style.
UPDATE
Instead you can draw an outer shadow on a smaller centered view which lies on top of your existing view.