当
[view.layer addSublayer:CAGradientLayer]
其他视图无法显示时 使用:
[view.layer insertSublayer:CAGradientLayer atIndex:0]
原因很简单 被挡住了 调整层次就好
示例:
UIColor *stateColor = [UIColor colorWithRed:230.0/255.0 green:150.0/255.0 blue:108.0/255.0 alpha:1.0];
UIColor *endColor = [UIColor colorWithRed:225.0/255.0 green:103.0/255.0 blue:229.0/255.0 alpha:1.0];
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = self.bounds;
//设置渐变色数组
[gradientLayer setColors:@[(__bridge id)stateColor.CGColor,(__bridge id)endColor.CGColor]];
//设置起点 终点 坐标
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1, 1);
//0.2表示数组中第一个颜色的结束点
//1.0表示数组中第二个颜色的结束点
gradientLayer.locations = @[@0.2,@1.0];
// 阴影颜色
gradientLayer.shadowColor = [UIColor blackColor].CGColor;
// 阴影偏移,默认(0, -3)
gradientLayer.shadowOffset = CGSizeMake(0,0);
// 阴影透明度,默认0
gradientLayer.shadowOpacity = 0.2;
// 阴影半径,默认3
gradientLayer.shadowRadius = 5.0;
// 设置视图圆角
gradientLayer.cornerRadius = 7.0;
[self.layer insertSublayer:gradientLayer atIndex:0];
self.clipsToBounds = NO;