I'm trying to make the ends of my UIScrollView fade out - just like one would a UITableView. I found the below code. I'm using it in a UIScrollView subclass in a method called inside initWithFrame:...
.
if (!maskLayer)
{
maskLayer = [CAGradientLayer layer];
CGColorRef outerColor = [UIColor colorWithWhite:0 alpha:1.0].CGColor;
CGColorRef innerColor = [UIColor colorWithWhite:1.0 alpha:0.0].CGColor;
maskLayer.colors = [NSArray arrayWithObjects:(__bridge id)outerColor,
(__bridge id)innerColor, (__bridge id)innerColor, (__bridge id)outerColor, nil];
maskLayer.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.2],
[NSNumber numberWithFloat:0.8],
[NSNumber numberWithFloat:1.0], nil];
maskLayer.bounds = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
maskLayer.anchorPoint = CGPointZero;
CGColorRelease(outerColor);
CGColorRelease(innerColor);
self.layer.mask = maskLayer;
}
NOTE: I've already seen this question, but I already have __bridge
before my colors.
I'm sure it's something really basic, but I just can't figure it out. I added the CGColorRelease
lines in hope that would fix it, but it didn't...
Does anyone see anything I don't?