【问题标题】:UIView shadow not workingUIView 阴影不起作用
【发布时间】:2012-05-10 04:24:24
【问题描述】:

这是我的代码。

listView.layer.masksToBounds = NO;
listView.layer.shadowOffset = CGSizeMake(-3, 3);
listView.layer.shadowColor=[[UIColor blackColor] CGColor];
listView.layer.shadowRadius = 4;
listView.layer.shadowOpacity = 1.0;
[listView.layer setShouldRasterize:YES];

阴影效果很好。

在变化中

listView.layer.masksToBounds = YES;

我没有得到阴影效果。

【问题讨论】:

    标签: iphone objective-c ios ios5


    【解决方案1】:

    阴影实际上是在 UIView 下方绘制的。如果您将 maskToBounds 设置为 YES,这将剪辑 UIView 框架之外的任何绘图。 Here is a SO link that describes this in more detail.

    【讨论】:

      【解决方案2】:

      阴影绘制在图层边界之外。你必须设置listView.layer.masksToBounds = NO才能看到阴影

      如果你设置了listView.layer.masksToBounds = YES,你就不能在边界之外绘制任何东西,所以你不能得到阴影

      【讨论】:

      • 这是最有帮助的。谢谢
      【解决方案3】:

      只有以下对我有用

      [self.view bringSubviewToFront:subView];
      

      【讨论】:

        【解决方案4】:

        如果您必须使用masksToBounds = YES;,请查看this SO post。它告诉您如何通过使用两个嵌套视图在视图上同时使用阴影和圆角(在这种特殊情况下):外部视图投射阴影并且不遮罩边界,而内部视图具有圆角和遮罩边界。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-04-30
          • 2014-07-08
          • 2011-11-21
          相关资源
          最近更新 更多