1获取渐变色,获取渐变的方法有好几种,之所以选择用颜色生成图片,再从图片获取颜色,是因为我的内容不是固定的,如果用一张固定的渐变色获取颜色是不可取。还有一个方法用layer,也不太好,最终选择了这种
+(UIImage *)getImageWithColors:(NSArray *)colors
withBounds:(CGRect)bounds{
NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:colors.count];
for (UIColor *color in colors) {
[mutableArray addObject:(__bridge id)color.CGColor];
}
UIGraphicsBeginImageContextWithOptions(bounds.size, NO, [UIScreen mainScreen].scale);
CGContextRef context = UIGraphicsGetCurrentContext();
//绘制渐变层
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradientRef = CGGradientCreateWithColors(colorSpaceRef,
(__bridge CFArrayRef)[mutableArray copy],
NULL);
CGPoint startPoint = CGPointZero;
CGPoint endPoint = CGPointMake(CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
CGContextDrawLinearGradient(context, gradientRef, startPoint, endPoint, kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
//取到渐变图片
UIImage *gradientImage = UIGraphicsGetImageFromCurrentImageContext();
//释放资源
CGColorSpaceRelease(colorSpaceRef);
CGGradientRelease(gradientRef);
UIGraphicsEndImageContext();
return gradientImage;
}
2闪烁效果,就是在加一个label,然后用一个layer,进行动画。