Shadow effects on ImageView in iOS(iOS 中 ImageView 的阴影效果)
问题描述
我正在尝试为我的 Imageview 提供阴影效果,就像在这张图片中一样.
I am trying to provide a shadow effect to my Imageview just like in this image.
但我面临的问题是阴影实际上从 Imageview 的底部可见.
but the problem which I am facing it is that the shadow is actually visible from the bottom of the Imageview.
这是我添加阴影的代码.颜色和所有仍然与这个不匹配.
Here is the code which I have done to add the shadow. The color and all is still not matching with this one.
CAGradientLayer *shadow = [CAGradientLayer layer];
shadow.frame = CGRectMake(-100, 70, perspectiveView.frame.size.width,
perspectiveView.frame.size.height - 20);
shadow.startPoint = CGPointMake(1.0, 0.5);
shadow.endPoint = CGPointMake(0, 0.5);
shadow.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithWhite:0.0
alpha:0.4f] CGColor], (id)[[UIColor clearColor] CGColor], nil];
shadow.opacity = 1.0f;
[perspectiveView.layer addSublayer:shadow];
请提供输入.此外,如果方法是错误的,请随时指导我采用任何其他方法.提前致谢.
Please provide inputs. Also if the approach is wrong, feel free to guide me to any other approach. Thanks in advance.
还有人可以建议如何提供 3D 边框,就像在图像中为图像视图提供轻微宽度一样?
Also can anyone suggest how to provide a 3D border just like in the image which provides a slight width to the image view?
推荐答案
也许,给图层添加阴影似乎可行.你可能想尝试这样的事情:
Perhaps, adding a shadow to the layer seems to work. You may want to try something like this:
// perspectiveView.transform = CGAffineTransformMakeRotation(-50.0f);
perspectiveView.layer.shadowOffset = CGSizeMake(10, 10);
perspectiveView.layer.shadowRadius = 5.0;
perspectiveView.layer.shadowOpacity = 0.6;
perspectiveView.layer.masksToBounds = NO;
您需要使用这些值来满足您的要求.希望这可以帮助.
You will need to playaround with these values to match your requirements. Hope this helps.
这是我的输出:
这篇关于iOS 中 ImageView 的阴影效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS 中 ImageView 的阴影效果
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01