我不明白如何删除添加到视图中的阴影.我以initWithFrame这种方式在阴影中添加到我的视图中:
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];
Run Code Online (Sandbox Code Playgroud)
在执行应用程序后,我想从此视图中删除阴影.我尝试过使用:
layer.hidden = YES;
Run Code Online (Sandbox Code Playgroud)
要么
self.layer.hidden = YES;
Run Code Online (Sandbox Code Playgroud)
但这完全隐藏了视图,而不仅仅是添加了阴影.
有没有办法从视图中检索添加的阴影然后隐藏它?谢谢!
Gui*_*gis 34
我想你可以使用你的shadowOpacity属性CALayer.
所以这应该工作:
self.layer.shadowOpacity = 0.0;
Run Code Online (Sandbox Code Playgroud)
并显示你的影子使用:
self.layer.shadowOpacity = 1.0;
Run Code Online (Sandbox Code Playgroud)
对不起,不确定方法是否正确,但您是否尝试过更改属性layer shadow?例如,其中一个;
layer.shadowOffset = CGSizeMake(0, 0);
layer.shadowColor = [[UIColor clearColor] CGColor];
layer.cornerRadius = 0.0f;
layer.shadowRadius = 0.0f;
layer.shadowOpacity = 0.00f;
Run Code Online (Sandbox Code Playgroud)
斯威夫特 4.2
我在我的标签和导航栏代码中使用它。
extension UIView {
func shadow(_ height: Int = 5) {
self.layer.masksToBounds = false
self.layer.shadowRadius = 4
self.layer.shadowOpacity = 1
self.layer.shadowColor = UIColor.gray.cgColor
self.layer.shadowOffset = CGSize(width: 0 , height: height)
}
func removeShadow() {
self.layer.shadowOffset = CGSize(width: 0 , height: 0)
self.layer.shadowColor = UIColor.clear.cgColor
self.layer.cornerRadius = 0.0
self.layer.shadowRadius = 0.0
self.layer.shadowOpacity = 0.0
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20149 次 |
| 最近记录: |