当前位置: 首页 > news >正文

iOS之CAGradientLayer属性简介和使用

1、CAGradientLayer简介

  CAGradientLayer用于制作背景图层的颜色渐变,也就是颜色梯度!相关属性简介:

#import <QuartzCore/CALayer.h>
#import <Foundation/NSArray.h>

NS_ASSUME_NONNULL_BEGIN

CA_CLASS_AVAILABLE (10.6, 3.0, 9.0, 2.0)
@interface CAGradientLayer : CALayer

//颜色数组 CGColor
@property(nullable, copy) NSArray *colors;

//颜色区间范围数组,范围是[0-1]并且是递增
@property(nullable, copy) NSArray<NSNumber *> *locations;

//开始坐标和结束坐标 范围(0-1)
//默认值(0.5,0.0) (0.5,1.0)
@property CGPoint startPoint;
@property CGPoint endPoint;

//绘制类型,目前只有一个参数也是默认值kCAGradientLayerAxial
@property(copy) NSString *type;

@end

/** `type' values. **/

CA_EXTERN NSString * const kCAGradientLayerAxial
CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);

NS_ASSUME_NONNULL_END

 

2、CAGradientLayer的简单使用:

    self.showView = [[UIView alloc] initWithFrame:CGRectMake(100,(CScreenHeight-200)/2,CScreenWidth-200,200)];
    CAGradientLayer *layer = [CAGradientLayer layer];
    layer.frame = CGRectMake(0,0,CScreenWidth-200,200);
    layer.colors = @[(id)UIColor.redColor.CGColor,
                     (id)UIColor.whiteColor.CGColor,
                     (id)UIColor.redColor.CGColor];
    layer.locations = @[@(-0.2),@(-0.1),@0];
    layer.startPoint = CGPointMake(0, 0);
    layer.endPoint = CGPointMake(1, 1);
    layer.type = kCAGradientLayerAxial;
    [self.showView.layer addSublayer:layer];
    self.layer = layer;
    self.showView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.showView];
    self.waterTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(waterAction) userInfo:nil repeats:YES];

- (void)waterAction{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"locations"];
    animation.fromValue = @[@(-0.3), @(-0.2), @(0)];
    animation.toValue   = @[@(1.0), @(1.2), @(1.3)];
    animation.duration  = 1;
    [self.layer addAnimation:animation forKey:nil];
}

效果图

 

转载于:https://www.cnblogs.com/xianfeng-zhang/p/7754099.html

相关文章:

  • 近百年前宝洁发明“肥皂剧”,阿里要创造“种草剧”!
  • python 字符框
  • SpringMVC学习系列 之 数据验证
  • easyui-combobox 设置option内容不换行
  • 3.7 su命令 3.8 sudo命令 3.9 限制root远程登录
  • fs检测文件夹状态
  • webapi 获取请求参数
  • 风险管理:企业要为云端的5种风险承担责任
  • 分享关于Entity Framework 进行CRUD操作实验的结果
  • 文件地理数据库的大小和名称限制
  • OID
  • Hyper-V Server 2012 R2介绍
  • 单例模式--SingleTon
  • BZOJ-1853: [Scoi2010]幸运数字 (容斥原理)
  • ORA-01950: no privileges on tablespace
  • ES6--对象的扩展
  • JAVA_NIO系列——Channel和Buffer详解
  • JavaScript对象详解
  • MySQL常见的两种存储引擎:MyISAM与InnoDB的爱恨情仇
  • Redis的resp协议
  • REST架构的思考
  • spring boot 整合mybatis 无法输出sql的问题
  • 工作踩坑系列——https访问遇到“已阻止载入混合活动内容”
  • 关于字符编码你应该知道的事情
  • 世界编程语言排行榜2008年06月(ActionScript 挺进20强)
  • 跳前端坑前,先看看这个!!
  • 用 vue 组件自定义 v-model, 实现一个 Tab 组件。
  • 【运维趟坑回忆录 开篇】初入初创, 一脸懵
  • 阿里云IoT边缘计算助力企业零改造实现远程运维 ...
  • 移动端高清、多屏适配方案
  • ​ubuntu下安装kvm虚拟机
  • ​七周四次课(5月9日)iptables filter表案例、iptables nat表应用
  • (Java岗)秋招打卡!一本学历拿下美团、阿里、快手、米哈游offer
  • (Redis使用系列) Springboot 在redis中使用BloomFilter布隆过滤器机制 六
  • (八)c52学习之旅-中断实验
  • (二)Linux——Linux常用指令
  • (更新)A股上市公司华证ESG评级得分稳健性校验ESG得分年均值中位数(2009-2023年.12)
  • (汇总)os模块以及shutil模块对文件的操作
  • (区间dp) (经典例题) 石子合并
  • (未解决)macOS matplotlib 中文是方框
  • (转载)(官方)UE4--图像编程----着色器开发
  • (转载)利用webkit抓取动态网页和链接
  • .NET 8 编写 LiteDB vs SQLite 数据库 CRUD 接口性能测试(准备篇)
  • .NET CLR基本术语
  • .net core 6 集成 elasticsearch 并 使用分词器
  • .Net Redis的秒杀Dome和异步执行
  • .net 托管代码与非托管代码
  • .NET/C# 的字符串暂存池
  • .ui文件相关
  • /dev/sda2 is mounted; will not make a filesystem here!
  • ??myeclipse+tomcat
  • @Not - Empty-Null-Blank
  • @RequestBody详解:用于获取请求体中的Json格式参数
  • @TableId注解详细介绍 mybaits 实体类主键注解
  • [.net]官方水晶报表的使用以演示下载