美文网首页iOS
iOS app图片添加遮罩效果

iOS app图片添加遮罩效果

作者: 打不死的小怪兽 | 来源:发表于2016-12-26 11:44 被阅读611次
屏幕快照 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图片添加遮罩效果

    本文链接:https://www.haomeiwen.com/subject/aggzuttx.html