您好,我喜欢添加一个CALayer阴影到一个视图,其中的阴影是视图的左右,最简单的方法是:
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时,它看起来不太好。我怎样才能使阴影在左右两边看起来都很好。
发布于 2013-01-09 00:34:58
我认为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;如果您只希望阴影位于左侧和右侧,则在顶部和底部插入矩形,以便顶部和底部的阴影隐藏在视图后面:
CGRect shadowRect = CGRectInset(someView.bounds, 0, 4); // inset top/bottom
someView.layer.shadowPath = [[UIBezierPath bezierPathWithRect:shadowRect] CGPath];我不确定这是不是你想要的。
发布于 2017-07-06 17:20:52
swift 3.0版本
imageView.layer.shadowOpacity = 0.8
imageView.layer.shadowOffset = CGSize(width: 0, height: 3)
imageView.layer.shadowRadius = 4.0
let shadowRect: CGRect = imageView.bounds.insetBy(dx: 0, dy: 4)
imageView.layer.shadowPath = UIBezierPath(rect: shadowRect).cgPath发布于 2016-06-27 21:46:42
progrmr的回答非常有帮助,干杯!
我做了一个滑出式菜单,我有一个问题,我的VC周围的阴影和扰乱导航栏。原来我不得不插入阴影层。
这是我使用的解决方案:
rightViewController!.view.layer.shadowOpacity = 0.8
rightViewController!.view.layer.shadowOffset = CGSizeMake(0, 3)
rightViewController!.view.layer.shadowRadius = 4.0
let shadowRect: CGRect = CGRectInset(rightViewController!.view.bounds, 0, 4); // inset top/bottom
rightViewController!.view.layer.shadowPath = UIBezierPath(rect: shadowRect).CGPathhttps://stackoverflow.com/questions/14219412
复制相似问题