ios控件渐变色的处理
+(CAGradientLayer *)gradientColorWithBounds:(CGRect)bounds startColorHexString:(NSString *)startColor endColorHexString:(NSString *)endColor { CAGradientLayer *gradientLayer = [CAGradientLayer layer]; gradientLayer.colors = @[(__bridge id)[UIColor colorWithHexString:startColor].CGColor, (__bridge id)[UIColor colorWithHexString:endColor].CGColor]; gradientLayer.locations = @[@0, @1]; gradientLayer.startPoint = CGPointMake(0, 0); gradientLayer.endPoint = CGPointMake(1.0, 1.0); gradientLayer.frame = bounds; return gradientLayer; }
以上代码就是比较自然的设置渐变色的方法,关于是否会自然润滑的渐变主要看 locations startPoint endPoint 3个属性的设置值
by:初光夫