2015-05-29 48 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

我弄糟了座標。固定! –