美文网首页
000-CALayer阴影

000-CALayer阴影

作者: 紫荆秋雪_文 | 来源:发表于2016-12-21 14:12 被阅读34次

    1、通过设置CALayer来给视图控件添加阴影

    
    #import "ViewController.h"
    
    @interface ViewController ()
    
    /**
     *  测试View
     */
    @property (nonatomic, strong) UIView *testView;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        self.testView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
        self.testView.backgroundColor = [UIColor orangeColor];
        
        //0、圆角
        self.testView.layer.cornerRadius = 5;
        //1、设置图层阴影的范围
        self.testView.layer.shadowRadius = 10;
        //2、设置图层阴影的偏移量
        self.testView.layer.shadowOffset = CGSizeMake(10, -10);
        //3、设置图层阴影的颜色
        self.testView.layer.shadowColor = [UIColor blackColor].CGColor;
        //4、设置图层阴影的透明度
        self.testView.layer.shadowOpacity = 0.7;
        //5、添加边框宽度
        self.testView.layer.borderWidth = 3.0;
        //6、添加边框颜色
        self.testView.layer.borderColor = [UIColor blackColor].CGColor;
        
        [self.view addSubview:self.testView];
    }
    
    

    2、效果如下:

    QQ20161221-1@2x.png

    相关文章

      网友评论

          本文标题:000-CALayer阴影

          本文链接:https://www.haomeiwen.com/subject/uvsqvttx.html