zoukankan      html  css  js  c++  java
  • CALayer 图层

     

        

        // CALayer 图层属性,继承UIView都有该属性,可设置边框宽度、颜色、圆角、阴影等

        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 150)];

        imageView.image = [UIImage imageNamed:@"test.jpg"];

        

        // 边框宽度、颜色

        imageView.layer.borderWidth = 5;

        imageView.layer.borderColor = [UIColor redColor].CGColor;

        // 边框圆角

        imageView.layer.cornerRadius = 20;

        // 边框圆角超出部分隐藏 设置该属性后,阴影设置无效

    //    imageView.layer.masksToBounds = YES;

        // 阴影

        imageView.layer.shadowColor = [UIColor blackColor].CGColor;

        imageView.layer.shadowOffset = CGSizeMake(5, 5);

        imageView.layer.shadowOpacity = 0.5;

        [self.view addSubview:imageView];

        

        

        // CALayer 创建、显示

        // 比较UIView,CALayer不能处理事件,更加轻量级

        CALayer *newLayer = [CALayer layer]; // 创建

        newLayer.bounds = CGRectMake(100, 330, 200, 150); // 位置 必须设置

        newLayer.position = CGPointMake(100, 330); // 位置 必须设置

        // anchorPoint 定义的是CALayer中的点定在position位置 0-1,默认(0.5,0.5)是中心点 (0,0)是左上顶点 1,1)右下点

        newLayer.anchorPoint = CGPointMake(0, 0.5);

        

        newLayer.contents = (id)[UIImage imageNamed:@"test.jpg"].CGImage;

        newLayer.borderColor = [UIColor blackColor].CGColor;

        newLayer.borderWidth = 5;

        newLayer.cornerRadius = 10;

        newLayer.masksToBounds = YES;

        

        [self.view.layer addSublayer:newLayer];

  • 相关阅读:
    python,生产环境安装
    neo4j 图数据库
    RNN系列
    机器学习关于AUC的理解整理
    fensorflow 安装报错 DEPENDENCY ERROR
    dubbo Failed to check the status of the service com.user.service.UserService. No provider available for the service
    使用hbase遇到的问题
    MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk
    gradle 安装
    jenkins 安装遇到的坑
  • 原文地址:https://www.cnblogs.com/xiangjune/p/4972768.html
Copyright © 2011-2022 走看看