美文网首页
渐变色View

渐变色View

作者: 小小白衣 | 来源:发表于2017-09-28 17:23 被阅读0次
        [self.view addSubview:view];
        //初始化
        CAGradientLayer *gradLayer = [CAGradientLayer layer];
        //渐变颜色数组
        gradLayer.colors = @[(__bridge id)[UIColor redColor].CGColor,(__bridge id)[UIColor greenColor].CGColor,(__bridge id)[UIColor purpleColor].CGColor];
        //渐变色分段
        gradLayer.locations = @[@0.3,@0.6,@1];
        
        //从左上角到右下角
        gradLayer.startPoint = CGPointMake(0, 0);
        gradLayer.endPoint = CGPointMake(1, 1);
        
        //从左到右
        gradLayer.startPoint = CGPointMake(0, 0.5);
        gradLayer.endPoint = CGPointMake(0.5, 0.5);
        //farme
        gradLayer.frame = view.bounds;
        
        [view.layer addSublayer:gradLayer];
    

    效果图:从左到右


    Snip20170928_2.png

    相关文章

      网友评论

          本文标题:渐变色View

          本文链接:https://www.haomeiwen.com/subject/sfrvextx.html