首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UIView左侧和右侧的阴影

UIView左侧和右侧的阴影
EN

Stack Overflow用户
提问于 2013-01-09 00:19:53
回答 4查看 22.4K关注 0票数 6

您好,我喜欢添加一个CALayer阴影到一个视图,其中的阴影是视图的左右,最简单的方法是:

代码语言:javascript
复制
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时,它看起来不太好。我怎样才能使阴影在左右两边看起来都很好。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-01-09 00:34:58

我认为10是一个相当大的阴影半径,尝试3或4,也是我通常使用0.7的不透明度:

代码语言:javascript
复制
someView.layer.shadowColor = [[UIColor blackColor] CGColor];
someView.layer.shadowOffset = CGSizeMake(0.0f,0.0f);
someView.layer.shadowOpacity = 0.7f;
someView.layer.shadowRadius = 4.0f;

如果您只希望阴影位于左侧和右侧,则在顶部和底部插入矩形,以便顶部和底部的阴影隐藏在视图后面:

代码语言:javascript
复制
CGRect shadowRect = CGRectInset(someView.bounds, 0, 4);  // inset top/bottom
someView.layer.shadowPath = [[UIBezierPath bezierPathWithRect:shadowRect] CGPath];

我不确定这是不是你想要的。

票数 30
EN

Stack Overflow用户

发布于 2017-07-06 17:20:52

swift 3.0版本

代码语言:javascript
复制
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
票数 8
EN

Stack Overflow用户

发布于 2016-06-27 21:46:42

progrmr的回答非常有帮助,干杯!

我做了一个滑出式菜单,我有一个问题,我的VC周围的阴影和扰乱导航栏。原来我不得不插入阴影层。

这是我使用的解决方案:

代码语言:javascript
复制
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).CGPath
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14219412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档