iOS app图片添加遮罩效果

iOS app图片添加遮罩效果_第1张图片
屏幕快照 2016-12-26 上午11.38.53.png
CGColorRef opaqueBlackColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1].CGColor;
CGColorRef transparentBalckColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4].CGColor;
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0,250, 300, 50)];
label.text = @"颜色渐变的肯定面对面的,的目的顶顶顶顶";
label.textColor = [UIColor whiteColor];
label.font = [UIFont systemFontOfSize:18];
[imageView addSubview:label];
//初始化渐变层
_gradientLayer = [CAGradientLayer layer];
_gradientLayer.frame = CGRectMake(0, 250, imageView.frame.size.width, 50);
//设置渐变颜色方向
_gradientLayer.startPoint = CGPointMake(0, 1);
_gradientLayer.endPoint = CGPointMake(0, 0);
//设置颜色组
_gradientLayer.colors = @[(__bridge id)opaqueBlackColor,(__bridge id)transparentBalckColor];
[imageView.layer insertSublayer:_gradientLayer atIndex:0];

你可能感兴趣的:(iOS app图片添加遮罩效果)