一.
1.@interface LMStoreTableViewCell ()
{
CAGradientLayer *_gradientLayer;
}
2.
//1.设置渐变色 gradient(梯度)
_gradientLayer = [CAGradientLayer layer]; // 设置渐变效果
_gradientLayer.frame = self.bottomBgView.bounds;//注意等视图渲染之后再设置frame - (void) layoutSubviews
_gradientLayer.colors = [NSArray arrayWithObjects:
(id)[[UIColor clearColor] CGColor],
(id)[[UIColor blackColor] CGColor], nil];
_gradientLayer.startPoint = CGPointMake(0.0, 0.0);
_gradientLayer.endPoint = CGPointMake(0.0, 1.0);
[self.bottomBgView.layer insertSublayer:_gradientLayer atIndex:0];
二.
主要用到了Layer上的渐变层
//Transparent Gradient Layer
- (void) insertTransparentGradient {
UIColor *colorOne = [UIColor colorWithRed:(33/255.0) green:(33/255.0) blue:(33/255.0) alpha:0.0];
UIColor *colorTwo = [UIColor colorWithRed:(33/255.0) green:(33/255.0) blue:(33/255.0) alpha:1.0];
NSArray *colors = [NSArray arrayWithObjects:(id)colorOne.CGColor, colorTwo.CGColor, nil nil];
NSNumber *stopOne = [NSNumber numberWithFloat:0.0];
NSNumber *stopTwo = [NSNumber numberWithFloat:1.0];
NSArray *locations = [NSArray arrayWithObjects:stopOne, stopTwo, nil nil];
//crate gradient layer
CAGradientLayer *headerLayer = [CAGradientLayer layer];
headerLayer.colors = colors;
headerLayer.locations = locations;
headerLayer.frame = self.bounds;
[self.layer insertSublayer:headerLayer atIndex:0];
}
//color gradient layer
- (void) insertColorGradient {
UIColor *colorOne = [UIColor colorWithRed:(255/255.0) green:(255/255.0) blue:(255/255.0) alpha:1.0];
UIColor *colorTwo = [UIColor colorWithRed:(33/255.0) green:(33/255.0) blue:(33/255.0) alpha:1.0];
NSArray *colors = [NSArray arrayWithObjects:(id)colorOne.CGColor, colorTwo.CGColor, nil nil];
NSNumber *stopOne = [NSNumber numberWithFloat:0.0];
NSNumber *stopTwo = [NSNumber numberWithFloat:1.0];
NSArray *locations = [NSArray arrayWithObjects:stopOne, stopTwo, nil nil];
CAGradientLayer *headerLayer = [CAGradientLayer layer];
headerLayer.colors = colors;
headerLayer.locations = locations;
headerLayer.frame = self.bounds;
[self.layer insertSublayer:headerLayer above:0];
}