我想将阴影设置为我的容器 UIView。
我用这段代码来实现它:
- (id)initWithCoder:(NSCoder*)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
//-> drop shadow
[self.layer setShadowColor:[UIColor blackColor].CGColor];
[self.layer setShadowOpacity:0.6];
[self.layer setShadowRadius:2.0];
[self.layer setShadowOffset:CGSizeMake(2.0, 2.0)];
}
return self;
}
这效果很好。但是,当我使用_containerView.clipsToBounds = YES;
在这个容器 UIView 上,我看不到我的影子。为什么?
the clipsToBounds
还可以剪掉你的影子。为了防止这种情况,您可以添加_containerView.layer.masksToBounds = NO
这会禁用子图层的剪切(查看更多here https://stackoverflow.com/questions/9761189/whats-the-best-way-to-add-a-drop-shadow-to-my-uiview).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)