160722界面的颜色透明度渐变

来源:互联网 发布:最新网络币 编辑:程序博客网 时间:2024/05/27 14:11

        UIView* signBg = [[UIViewalloc]init];

//        signBg.backgroundColor = [UIColor grayColor];

        signBg.frame =CGRectMake(0,kListHeight - kSignBgHeight,kPresentersImageHegiht, kSignBgHeight);

        [bgView addSubview:signBg];

        

        //开始颜色,透明度

        UIColor *colorOne = [UIColorcolorWithRed:(0.0green:(0.0blue:(0.0alpha:0.0];

        

        //结束颜色,透明度

        UIColor *colorTwo = [UIColorcolorWithRed:(0.0green:(0.0blue:(0.0alpha:0.4];

        NSArray *colors = [NSArrayarrayWithObjects:(id)colorOne.CGColor, colorTwo.CGColor,nil];

        

        //crate gradient layer

        CAGradientLayer *headerLayer = [CAGradientLayerlayer];

        headerLayer.frame =CGRectMake(0,0, kPresentersImageHegiht,kSignBgHeight);

        headerLayer.colors = colors;

        

        //根据颜色值数组,设置颜色开始渐变的位置,如果是x轴渐变,最左边0.0,最右边是1,中间是介于01之前。

        headerLayer.locations =@[@(0.0),@(1.0)];

        

        //左上角(0,右下角(1,1)

        headerLayer.startPoint =CGPointMake(0,0);

        headerLayer.endPoint =CGPointMake(0,1);

        [signBg.layeraddSublayer:headerLayer];

0 0