阴影 UIview 和 clipsToBounds [英] Shadow UIview and clipsToBounds

查看:99
本文介绍了阴影 UIview 和 clipsToBounds的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的容器 UIView 设置阴影.我用这个代码来制作它:

I would like to set the shadow to my container UIView. I use this code to make it:

- (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;
}

这很好用.但是,当我在这个容器 UIView 上使用 _containerView.clipsToBounds = YES; 时,我看不到我的影子.为什么?

This works well. But, when I use _containerView.clipsToBounds = YES; on this container UIView, I can't see my shadow. Why?

推荐答案

clipsToBounds 也会剪辑你的影子.为了防止这种情况,您可以添加 _containerView.layer.masksToBounds = NO 以禁用子图层的剪辑(请参阅更多 此处).

the clipsToBounds also clips your shadow. In order to prevent this you can add _containerView.layer.masksToBounds = NO which disables clipping of sublayers (see more here).

这篇关于阴影 UIview 和 clipsToBounds的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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