首页 > 其他分享 >OC CAGradientLayer 渐变色

OC CAGradientLayer 渐变色

时间:2023-09-23 14:57:46浏览次数:36  
标签:__ bridge 渐变色 gradientLayer OC CAGradientLayer self 255

 

 

 

@property (nonatomic, strong)  NSTimer *timer; /**< 定时器 */
@property (strong, nonatomic) CAGradientLayer *gradientLayer; /**< 渐变层 */




    [self.layer insertSublayer:self.gradientLayer atIndex:0];
    // 初始化定时器
      self.timer = [NSTimer scheduledTimerWithTimeInterval:1.f
                                                target:self
                                              selector:@selector(respondsToTimerEvent)
                                              userInfo:nil
                                               repeats:YES];





- (void)respondsToTimerEvent {

    // 设定颜色组动画
    
    self.gradientLayer.colors = @[(__bridge id)[UIColor clearColor].CGColor,
                                  (__bridge id)[UIColor colorWithRed:arc4random()%255 / 255.f
                                                               green:arc4random()%255 / 255.f
                                                                blue:arc4random()%255 / 255.f
                                                               alpha:1].CGColor];
    // 设置颜色分割点动画
    self.gradientLayer.locations = @[@(arc4random() %10 / 10.f), @(1.f)];
}





- (CAGradientLayer *)gradientLayer {
    if (!_gradientLayer) {

        // 初始化渐变层
        _gradientLayer       = [CAGradientLayer layer];
        _gradientLayer.frame = CGRectMake(0, 0, Screen_Width, Screen_Height);
        
        // 设置颜色渐变方向
        _gradientLayer.startPoint = CGPointMake(0, 0);
        _gradientLayer.endPoint   = CGPointMake(0, 1);

        // 设定颜色组
        _gradientLayer.colors = @[(__bridge id)[UIColor clearColor].CGColor,
                                  (__bridge id)[UIColor whiteColor].CGColor];

        // 设定颜色分割点
        _gradientLayer.locations = @[@(0.5f), @(1.f)];
    }
    return _gradientLayer;
}

 

 

参考:

https://blog.csdn.net/aotang2760/article/details/101111679

标签:__,bridge,渐变色,gradientLayer,OC,CAGradientLayer,self,255
From: https://www.cnblogs.com/qingzZ/p/17724377.html

相关文章

  • docker-compose 部署 phpmyadmin
    docker-compose.yamlversion:'3.9'services:phpmyadmin:image:phpmyadmincontainer_name:phpmyadminrestart:alwaysprivileged:trueenvironment:-PMA_HOST=192.168.0.152ports:-"8081:80"ne......
  • ROCKY 8 搭建本地yum源及配置局域网公用
    1.上传完整镜像文件 CRT软件,ALT+P打开上传界面,put命令进行上传,windows端命令在前面加L。1.将iso文件上传至/opt下。2.创建挂载目录3.挂载iso文件mount-oloop/opt/Rocky-8.4-x86_64-dvd1.iso/mnt/cdrom/4.修改配置yum源vim/etc/yum.repos.d/Rocky-Media.repo(修改......
  • git SSL certificate problem unable to get local issuer certificate
    gitSSLcertificateproblemunabletogetlocalissuercertificate这个问题是由于没有配置信任的服务器HTTPS验证。默认,cURL被设为不信任任何CAs,就是说,它不信任任何服务器验证。只需要执行下面命令就可以解决:gitconfig--globalhttp.sslVerifyfalse......
  • docker-compose 部署 RabbitMQ
    docker-compose部署RabbitMQdocker-compose.ymlversion:'3.5'services:rabbitmq:restart:alwaysimage:rabbitmq:managementcontainer_name:rabbitmqhostname:rabbitports:-5672:5672-15672:15672environm......
  • docker-compose 安装 redis
    docker-compose安装redisversion:"3.5"services:lcloud-redis:image:redis:6.2container_name:lcloud-redisrestart:alwaysports:-6379:6379安装运行#docker-composeup-d--build......
  • Docker 部署 Redis
    Docker部署Redis参考资料:史上最详细Docker安装Redis拉取镜像dockerpullredis:latest创建数据卷#创建本地映射目录mkdir-p/mydata/redis/data#创建本地映射文件touch/mydata/redis/conf/redis.conf参数说明:-p:多级目录创建启动容器dockerrun--restart=......
  • Docker 部署 zookeeper
    Docker部署zookeeper拉取ZooKeeper镜像最新版本dockerpullzookeeper:latest创建数据卷mkdir-p./zookeeper/datamkdir-p./zookeeper/confmkdir-p./zookeeper/logs运行容器dockerrun-d--namelcloud-zookeeper--privileged=true-p2181:2181--restart=alw......
  • Docker 部署 思源笔记
    Docker部署思源笔记参考文档:思源笔记群辉docker安装简略版(新手向)-链滴(ld246.com)思源笔记docker部署-建站教程(jiuaidu.com)‍拉取镜像dockerpullb3log/siyuan运行dockerrun --namesiyuan-it-d --restart=always -v/usr/local/software/siy......
  • Docker 部署 MySQL
    Docker部署MySQL参考资料:使用docker-compose的方式部署mysql拉取镜像dockerpullmysql:latest创建数据卷mkdir-p./mysql/datamkdir-p./mysql/initdbmkdir-p./mysql/log运行容器设置开机自启dockerrun\--namemysql\-d\-p3306:3306\-v./mysql/log......
  • Docker 部署 Nginx
    Docker部署Nginxdockerpullnginx:latestDocker来部署一个Nginx服务器dockerrun--restart=always-dp80:80-v./nginx/logs:/var/log/nginx-v/etc/localtime:/etc/localtime--namelcloud-nginxnginx:latest可以看到,Nginx服务器已经成功部署了,但是实际上我们并没......