Created
May 4, 2012 11:44
-
-
Save jk/2594321 to your computer and use it in GitHub Desktop.
UIScrollView fading gradient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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