记录几个 CALayer 的重要属性 (二)

记录几个 CALayer 的重要属性:

有关阴影配置
  • shadowColor : 配置阴影颜色
@property CGColorRef shadowColor;
/* The color of the shadow. Defaults to opaque black. Colors created
 * from patterns are currently NOT supported. Animatable. */

默认阴影颜色为黑色, 可以设置 ARGB, 默认值均是0, 可设置范围是[0, 1]之间.
typedef struct CGColor CGColorRef;//CGColorRef 就是 CGColor
shadowColor 的赋值方法如下:

subView.layer.shadowColor = [UIColor colorWithRed:arc4random() % 256 / 256.0 green:arc4random() % 256 / 256.0 blue:arc4random() % 256 / 256.0 alpha:arc4random() % 256 / 256.0].CGColor;// 获取一个随机颜色阴影
  • shadowOpacity : 配置阴影透明效果
@property float shadowOpacity;
/* The opacity of the shadow. Defaults to 0. Specifying a value outside the [0,1] range will give undefined results. Animatable. */

默认阴影不透明度为0.0, 0.0是透明的,1.0是不透明的.
shadowOpacity 的赋值方法:

subView.layer.shadowOpacity = 0.5;
  • shadowOffset : 配置阴影在 X, Y 轴上的 延伸
@property CGSize shadowOffset;
/* The shadow offset. Defaults to (0, 1). Animatable. */

配置阴影在 x, y 轴方向上的延伸,默认值为(0, 1)
关于阴影方向如下:
①在 x 轴的正半轴,则阴影在 subView 的右边
②在 x 轴的负半轴,则阴影在 subView 的左边
③在 y 轴的正半轴,则阴影在 subView 的下方
④在 y 轴的负半轴,则阴影在 subView 的上方
设置方法如下:

subView.layer.shadowOffset = CGSizeMake(10, 10);
  • shadowRadius : 配置阴影的渐变距离
@property CGFloat shadowRadius;
/* The blur radius used to create the shadow. Defaults to 3. Animatable. */

配置模糊半径, 默认值为3. 模糊半径越大, 阴影面积越大, 阴影越不清晰.
shadowRadius 的设置方法:

subView.layer.shadowRadius = 100;
  • shadowPath : 配置阴影的位置
@property CGPathRef shadowPath;
/* When non-null this path defines the outline used to construct the
 * layer's shadow instead of using the layer's composited alpha
 * channel. The path is rendered using the non-zero winding rule.
 * Specifying the path explicitly using this property will usually
 * improve rendering performance, as will sharing the same path
 * reference across multiple layers. Defaults to null. Animatable. */

设置阴影路径(位置和大小), 默认值为空, 这个路径的参考坐标系是 subView 的坐标系.
这里用到 UIBezierPath, 先不做过多说明.
shadowPath 的设置方法如下:

subView.layer.shadowPath = [UIBezierPath bezierPathWithRect:CGRectMake(100, 0, 10, 10)].CGPath;//该阴影的路径是在 subView 的坐标系的 x=100,y=0的位置开始创建一个(阴影)层,阴影大小是10*10的.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值