渐变色

 1 - (void)setupDurationLabelBgView
 2 {
 3     CGFloat bgimageViewWidth = 165 * kBigScreenViewWidthRate;
 4     CGFloat bgimageViewHeight = 20 * kBigScreenViewWidthRate;
 5 
 6     UIView *durationLabelBgView = [[UIView alloc] init];
 7     [_imgView addSubview:durationLabelBgView];
 8     [durationLabelBgView mas_makeConstraints:^(MASConstraintMaker *make) {
 9         make.left.right.bottom.mas_equalTo(_imgView);
10         make.height.mas_equalTo(bgimageViewHeight);
11     }];
12     UIColor *color1 = UIColorFromHexWithAlpha(0x000000, 0);
13     UIColor *color2 = UIColorFromHexWithAlpha(0x000000, 1);
14     CAGradientLayer *commonLayer = [self gradientLayerWithColor1:color1 color2:color2];
15     commonLayer.frame = CGRectMake(0, 0, bgimageViewWidth, bgimageViewHeight);
16     [durationLabelBgView.layer addSublayer:commonLayer];
17 }
18 
19 - (CAGradientLayer *)gradientLayerWithColor1:(UIColor *)color1 color2:(UIColor *)color2{
20     //初始化CAGradientlayer对象,使它的大小为UIView的大小
21     CAGradientLayer *gradientLayer = [CAGradientLayer layer];
22     
23     //设置渐变区域的起始和终止位置(范围为0-1)
24     gradientLayer.startPoint = CGPointMake(0, 0);
25     gradientLayer.endPoint = CGPointMake(1, 0);
26     
27     gradientLayer.colors = @[(__bridge id)color1.CGColor,
28                              (__bridge id)color2.CGColor];
29     //设置颜色分割点(范围:0-1)
30     gradientLayer.locations = @[@(0.0f), @(0.6)];
31     
32     return gradientLayer;
33 }

 

转载于:https://www.cnblogs.com/lz465350/p/7735991.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值