您好,我想将 CALayer 阴影添加到阴影位于 View 左侧和右侧的 View 中,最简单的方法是:
someView.layer.shadowColor = [[UIColor blackColor] CGColor];
someView.layer.shadowOffset = CGSizeMake(0.0f,0.0f);
someView.layer.shadowOpacity = 1.0f;
someView.layer.shadowRadius = 10.0f;
someView.layer.shadowPath = [[UIBezierPath bezierPathWithRect:someView.bounds] CGPath];
但是当我增加 shadowRadius 时,我会添加一个更大的阴影,就像阴影一样,它看起来不太好。我如何制作左右两侧看起来都不错的阴影。
最佳答案
我认为 10 是一个相当大的阴影半径,试试 3 或 4,不透明度我通常使用 0.7:
someView.layer.shadowColor = [[UIColor blackColor] CGColor];
someView.layer.shadowOffset = CGSizeMake(0.0f,0.0f);
someView.layer.shadowOpacity = 0.7f;
someView.layer.shadowRadius = 4.0f;
如果你只想在左边和右边有阴影,那么在顶部和底部插入矩形,这样顶部和底部的阴影就隐藏在你的 View 后面:
CGRect shadowRect = CGRectInset(someView.bounds, 0, 4); // inset top/bottom
someView.layer.shadowPath = [[UIBezierPath bezierPathWithRect:shadowRect] CGPath];
我不确定这是否是您想要的。
关于iphone - UIView左右阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14219412/