【问题标题】:Adding a shadow at the edge of the UIView(Picture inside)在 UIView 的边缘添加阴影(内图)
【发布时间】:2014-01-20 09:39:12
【问题描述】:

所以,我正在寻找最实用的方法来在 UIView 的边缘添加阴影,如下图所示。我尝试了一些我阅读的方法,但真的无法让它们按我的意愿工作。如果有人知道苹果如何在他们的应用程序中做到这一点,那就太好了。

图片链接(太大了,不想直接发在这里):Example image

【问题讨论】:

    标签: ios cocoa-touch uiview ios7 core-graphics


    【解决方案1】:
    - (void) configureSlideLayer:(CALayer *)layer
    {
        layer.shadowColor = [UIColor blackColor].CGColor;
        layer.shadowOpacity = 1;
        layer.shadowOffset = CGSizeMake(-3, 0);
        layer.shadowRadius = 5;
        layer.masksToBounds = 否;
        layer.shadowPath =[UIBezierPath bezierPathWithRect:layer.bounds].CGPath;
    }
    ...
    [自我configureSlideLayer:self.view.layer];
    

    来源:https://github.com/arturdev/AMSlideMenu

    【讨论】:

      【解决方案2】:

      以下属性处理 UIView 上的阴影:

      view.layer.shadowOpacity = 0.5;
      view.layer.shadowRadius = 25;
      view.layer.shadowColor = [UIColor blackColor].CGColor;
      view.layer.shadowOffset = CGSizeMake(-3, 0);
      

      该代码将生成一个半透明度的黑色阴影,阴影半径为 25 像素,并向左移动 3 个像素。您需要将以下导入添加到文件顶部:

      #import <QuartzCore/QuartzCore.h>
      

      如果还没有,您可能还需要将 QuartzCore 框架添加到您的项目中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-06
        • 2015-10-23
        • 2013-07-04
        • 2014-07-30
        • 2017-10-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多