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:初光夫

posted @ 2019-02-28 14:34  WidgetBox  阅读(521)  评论(0编辑  收藏  举报