iOS UI 之聊天室渐变蒙层效果

iOS UI 开发中,我们已接触过不少 layer 相关设置,如常见设置按钮的圆角效果

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.layer.cornerRadius = 5.0;
button.layer.masksToBounds = YES;

还有边框、阴影也都可以通过 CALayer 相关属性直接设置。今天要说的是一个渐变效果,举个栗子,在一些直播中我们可以看到聊天室上边有个透明度渐变效果,如下
在这里插入图片描述
这个时候没有办法直接通过 layer 属性配置出这种效果,而且 layer 配置的效果只能作用于当前视图,无法作用到子视图上,在这里透明度渐变实际需要作用到聊天室的 cell 上,即它的子视图,所以此时需要通过另一种方式设置。

iOS QuartzCore 框架中提供了一个 CAGradientLayer 类(CALayer 子类)用来设置渐变色,同时 UIView 视图类的 layer 属性也有个 mask 蒙层属性。官方的解释

/* A layer whose alpha channel is used as a mask to select between the
 * layer's background and the result of compositing the layer's
 * contents with its filtered background. Defaults to nil. When used as
 * a mask the layer's `compositingFilter' and `backgroundFilters'
 * properties are ignored. When set
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值