我有一个UIScrollView,需要底部渐变为透明,以避免内容突然截断。 UIScrollView的背景是自定义颜色。到目前为止,我已经实现了以下代码,但是图层显示的是白色而不是自定义颜色。我想要的效果如下图所示,只在底部实现渐变。
以下是我的代码:
由于某种原因,该图层显示为白色,并且仅有scrollView宽度的一半。
![This is what I am going for, but only on the bottom](https://istack.dev59.com/b1RjO.webp)
maskLayer = [CAGradientLayer layer];
CGColorRef firstColor = [UIColor colorWithRed:141 green:211 blue:244 alpha:1.0].CGColor;
CGColorRef secondColor = [UIColor colorWithRed:141 green:211 blue:244 alpha:0.8].CGColor;
CGColorRef thirdColor = [UIColor colorWithRed:141 green:211 blue:244 alpha:0.2].CGColor;
CGColorRef fourthColor = [UIColor colorWithRed:141 green:211 blue:244 alpha:0.0].CGColor;
maskLayer.colors = [NSArray arrayWithObjects:(__bridge id)firstColor, (__bridge id)secondColor, (__bridge id)thirdColor, (__bridge id)fourthColor, nil];
maskLayer.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.2],
[NSNumber numberWithFloat:0.8],
[NSNumber numberWithFloat:1.0], nil];
maskLayer.frame = CGRectMake(0, 285, self.loginScrollView.frame.size.width, 40);
maskLayer.anchorPoint = CGPointZero;
[self.loginScrollView.layer addSublayer:maskLayer];
由于某种原因,该图层显示为白色,并且仅有scrollView宽度的一半。