在 UIImage 上为文本创建渐变

Create gradient on UIImage for text

我正在尝试复制在这些专辑插图图像视图底部找到的渐变。无论背景如何,都可以轻松阅读文本。

我该如何重新创建这个?

渐变效果称为地板淡化。

渐变从图像中间的 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];