iphone - UIView左右阴影

标签 iphone ios calayer shadow

您好,我想将 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/

相关文章:

objective-c - 使 NSView 不在其边界之外剪辑 subview

iphone - 用于 iPhone 到 Mac 集成的 CFNetwork 和 Bonjour 集成

ios - 无法将排序的字典序列化为 JSON - Swift 3

iphone - 来自图像的自定义 UIToolBar

ios - 在 UINavigationController 中推送 View Controller

iphone - 通过iPhone配置实用程序安装应用程序时出错

objective-c - iPad 3 shouldRasterize = YES 使 UILabel 文本被截断

iphone - 传递给drawLayer的上下文是什么:inContext:?

iphone - 检查以编程方式生成的 ImageView 的相交

iphone - 后台的 Restkit 对象映射