简体   繁体   English

UIView内的阴影

[英]Shadow inside UIView

I am working on iPhone application development and have come across shadows of UIView. 我正在从事iPhone应用程序开发,遇到过UIView的阴影。

I know how to show shadows to a UIView but what I am actually interested in is to drop shadow inside the UIView. 我知道如何向UIView显示阴影,但是我真正感兴趣的是在UIView中放置阴影。

Like when I set shadow properties of a UIView the shadow is dropped behind the view. 就像我设置UIView的阴影属性时一样,阴影被放置在视图后面。 I want it to come over the view so that the view looks as if it is pressed inside. 我希望它越过视图,以便该视图看起来好像被按下了一样。

Example of such view is UITextField with roundedRect styling. 这种视图的示例是具有roundedRect样式的UITextField。

Thanks, 谢谢,

It depends a lot on the final effect you want to achieve. 这很大程度上取决于您要达到的最终效果。

The easies way would be a custom image with a prebacked shadow as background. 简便的方法是将自定义图像作为背景,并添加预阴影。 This will give the illusion of a recession in the surface of the view. 这将给视图表面带来衰退的错觉。 You can then add subviews to it as usual. 然后,您可以照常向其添加子视图。

Alternatively, you can override the drawRect: method and draw the view as you like there, "inverted drop shadow" included. 另外,您可以覆盖drawRect:方法并在其中随意绘制视图,其中包括“倒影”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM