给view添加渐变色

2020-05-26  本文已影响0人  夜半度微凉

//给view添加渐变色

+ (void)gradualChange:(UIView*)viewwithFirstColor:(UIColor*)firstColorwithSecondColor:(UIColor*)secondColor {//颜色渐变

    CAGradientLayer *gradientL = [CAGradientLayer layer];

    gradientL.frame= view.bounds;

    gradientL.startPoint=CGPointMake(0,0);

    gradientL.endPoint=CGPointMake(0,1.0);//从上到下: CGPointMake(0,1.0)   2. 从左到右: CGPointMake(1.0, 0);

    gradientL.colors = [NSArray arrayWithObjects:

                        (__bridgeid)firstColor.CGColor,

                        (__bridgeid)secondColor.CGColor,nil];

    [view.layeraddSublayer:gradientL];

}

上一篇 下一篇

猜你喜欢

热点阅读