码迷,mamicode.com
首页 > 其他好文 > 详细

渐变色

时间:2017-10-26 13:54:55      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:set   imageview   die   割点   mon   alpha   location   int   env   

 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 }

 

渐变色

标签:set   imageview   die   割点   mon   alpha   location   int   env   

原文地址:http://www.cnblogs.com/lz465350/p/7735991.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!