当背景颜色为透明色时,阴影不显示 [英] Shadow not showing when background color is clear color

查看:550
本文介绍了当背景颜色为透明色时,阴影不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的xib中创建了一个uiview,背景颜色为清晰的颜色。当我在视图层上应用阴影时,阴影不会出现。但是当我设置除了清晰颜色之外的背景颜色时,阴影就会显示出来。请帮忙。

I've created an uiview in my xib with background color as clear color. When I apply the shadow on the layer of the view, the shadow is not appearing. But when i set the background color other than clear color, shadow is showing. Please help.

这是我的代码

self.cView.layer.shadowColor=[UIColor whiteColor].CGColor;
self.cView.layer.shadowOffset=CGSizeZero;
self.cView.layer.shadowRadius=30.0;
self.cView.layer.shadowOpacity=1.0;
self.cView.layer.cornerRadius=10.0;


推荐答案

问题是,阴影实际上考虑到了'上面那层。如果它上面什么也没有阴影:阴影如何工作

The problem is, that shadow actually takes into account the 'upper' layer. If there's nothing on it there will be no shadow: How Shadows Work

编辑:

有此配方从粘贴箱中复制

view.layer.shadowColor = [UIColor colorWithWhite:.5 alpha:1].CGColor;
view.layer.shadowRadius = 4.0f;
view.layer.shadowPath = CGPathCreateWithRect(CGRectMake(0, 0, 50, 50), NULL);
view.layer.shadowOpacity = 1.0f;
view.layer.shadowOffset = CGSizeMake(1, 1);

但我怀疑这对你有什么用处:结果是涂有的视图阴影的颜色和它周围的阴影。

But I doubt this will be of any use to you: the result is a view 'painted' with color of a shadow and a shadow around it.

这篇关于当背景颜色为透明色时,阴影不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆