iOS在视图中添加/删除阴影 [英] iOS add / remove shadow from a view
本文介绍了iOS在视图中添加/删除阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不明白如何删除添加到视图中的阴影。
我以这种方式添加到 initWithFrame中的视图
阴影:
I do not understand how to remove a shadow that was added to a view.
I add to my view in initWithFrame
a shadow in this way:
self.layer.borderWidth = 2;
self.layer.borderColor = [UIColor clearColor].CGColor;
self.backgroundColor = [UIColor greenColor];
[self.layer setCornerRadius:8.0f];
CALayer *layer = self.layer;
layer.shadowOffset = CGSizeMake(2, 2);
layer.shadowColor = [[UIColor blackColor] CGColor];
layer.cornerRadius = 8.0f;
layer.shadowRadius = 3.0f;
layer.shadowOpacity = 0.80f;
layer.shadowPath = [[UIBezierPath bezierPathWithRect:layer.bounds] CGPath];
在执行应用程序后,我想从此视图中删除阴影。我尝试过使用:
After in the execution of the app I want to remove the shadow from this view. I've tried using:
layer.hidden = YES;
或
self.layer.hidden = YES;
但这会完全隐藏视图,而不仅仅是添加的阴影。
but this hides the view completely, not just the added shadow.
有没有办法从视图中检索添加的阴影然后隐藏它?
谢谢!
Is there a way to retrieve the added shadow from a view and then hide it? Thanks!
推荐答案
我想你可以使用 shadowOpacity
你的 CALayer的财产
。
所以这应该有效:
self.layer.shadowOpacity = 0.0;
参见 CALayer
's shadowOpacity
文档页面
See the CALayer
's shadowOpacity
documentation page
并显示您的影子使用:
self.layer.shadowOpacity = 1.0;
这篇关于iOS在视图中添加/删除阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文