2015-05-29 46 views
0

我在尝试复制在这些专辑图片图像视图底部找到的渐变。无论背景是什么,它都可以很容易地阅读文本。在UIImage上为文字创建渐变

我该如何重新创建它?

enter image description here

回答

3

梯度效应被称为一个地面褪色。

渐变从图像中间的0.0 alpha黑色开始,到图像底部大约0.2 alpha黑色。

你可以一个CAGradientLayer添加到您的图像,沿着线:

CAGradientLayer *bottomFade = [CAGradientLayer layer]; 
bottomFade.frame = CGRectMake(0.0, CGRectGetHeight(self.imageView.bounds), CGRectGetWidth(self.imageView.bounds), -(CGRectGetHeight(self.imageView.bounds)/2.0)); 
bottomFade.startPoint = CGPointMake(0.5, 1.0); 
bottomFade.endPoint = CGPointMake(0.5, 0.0); 
bottomFade.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithWhite:0.0 alpha:0.0f] CGColor], (id)[[UIColor colorWithWhite:0.0 alpha:0.2f] CGColor], nil]; 
[image.layer addSublayer:bottomFade]; 
+0

真棒感谢,一些奇怪的原因,淡出只拿起宽度和高度的一半。我只是把界限和高度和宽度乘以2. – Clip

+0

我弄糟了坐标。固定! –