困在UIImageView屏蔽多个图像

时间:2016-07-30 14:23:12

标签: ios objective-c iphone uiimageview uiimage

我正在进行UIImageView屏蔽。我想要的图像背景如下。

enter image description here

你可以看到文字“喜马拉雅凝胶”底部的黑色效果。

我想在每次添加图片时添加此效果。

所以如果有人知道解决方案请帮忙。

提前致谢。

1 个答案:

答案 0 :(得分:0)

您可以在UIImageView上使用渐变,只要您更改UIImage,渐变仍将保留。

- (void)addGradientToView:(UIView *)view
{
    CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.frame = CGRectMake(0, view.frame.size.height * 0.8, view.frame.size.width, view.frame.size.height * 0.2);
    gradient.colors = @[(id)[[UIColor clearColor] CGColor],
                        (id)[[UIColor blackColor] CGColor]];
    [view.layer insertSublayer:gradient atIndex:0];
}

渐变仅从视图底部(view.hieght * 0.8)开始,颜色清晰,并持续到最后将为黑色渐变。