view透明度渐变

主要用到了Layer上的渐变层,核心代码如下,关于CALayer的使用可参考


UIColor *colorOne = [UIColor colorWithRed:(33/255.0)  green:(33/255.0)  blue:(33/255.0)  alpha:1.0];

UIColor *colorTwo = [UIColor colorWithRed:(33/255.0)  green:(33/255.0)  blue:(33/255.0)  alpha:0.0];

NSArray *colors = [NSArray arrayWithObjects:(id)colorOne.CGColor, colorTwo.CGColor, nil];

NSNumber *stopOne = [NSNumber numberWithFloat:0.0];

NSNumber *stopTwo = [NSNumber numberWithFloat:1.0];

NSArray *locations = [NSArray arrayWithObjects:stopOne, stopTwo, nil];

CAGradientLayer *headerLayer = [CAGradientLayer layer];

headerLayer.colors = colors;

headerLayer.locations = locations;

headerLayer.frame = _banner_shadow.bounds;

[_banner_shadow.layer insertSublayer:headerLayer atIndex:0];

你可能感兴趣的:(view透明度渐变)