标签:
//给某个view增加颜色透明度渐变图层
- (void) insertTransparentGradient {
NSLog(@"%@",NSStringFromCGRect(self.imgView.bounds));
UIColor *colorOne = [UIColor colorWithRed:(33/255.0) green:(33/255.0) blue:(33/255.0) alpha:0.0];
UIColor *colorTwo = [UIColor colorWithRed:(255/255.0) green:(0/255.0) blue:(0/255.0) alpha:0.6];
NSArray *colors = [NSArray arrayWithObjects:(id)colorOne.CGColor, colorTwo.CGColor, nil,nil];
NSNumber *stopOne = [NSNumber numberWithFloat:0.0];
NSNumber *stopTwo = [NSNumber numberWithFloat:1.0];
NSArray *locations = [NSArray arrayWithObjects:stopOne, stopTwo, nil,nil];
//crate gradient layer
CAGradientLayer *headerLayer = [CAGradientLayer layer];
headerLayer.colors = colors;
headerLayer.locations = locations;
// headerLayer.frame = self.imgView.bounds;
headerLayer.frame = CGRectMake(0, 20, 212, 432);
[self.imgView.layer addSublayer:headerLayer];
}
效果图:
参考链接:哈哈
demo链接:https://yunpan.cn/Oc6qWDkjxVyQGE (提取码:8abf)
标签:
原文地址:http://www.cnblogs.com/gaoxiaoniu/p/5682072.html