Skip to content

Instantly share code, notes, and snippets.

@jk
Created May 4, 2012 11:44
Show Gist options
  • Save jk/2594321 to your computer and use it in GitHub Desktop.
Save jk/2594321 to your computer and use it in GitHub Desktop.
UIScrollView fading gradient
- (void)maskUIViewHorizontally:(UIView *)view {
view.layer.mask = nil;
_maskLayer = nil;
if (!_maskLayer) {
_maskLayer = [CAGradientLayer layer];
UIColor *outerColor = [UIColor colorWithWhite:1.0 alpha:0.0]; // transparent
UIColor *innerColor = [UIColor colorWithWhite:1.0 alpha:1.0]; // opaque
_maskLayer.colors = [NSArray arrayWithObjects:(id)[outerColor CGColor], (id)[innerColor CGColor],
(id)[innerColor CGColor], (id)[outerColor CGColor], nil];
_maskLayer.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.0125],
[NSNumber numberWithFloat:0.9875],
[NSNumber numberWithFloat:1.0], nil];
_maskLayer.startPoint = CGPointMake(0.0, 0.5);
_maskLayer.endPoint = CGPointMake(1.0, 0.5);
_maskLayer.bounds = view.bounds;
_maskLayer.anchorPoint = CGPointZero;
view.layer.mask = _maskLayer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment