渐变色View

2017-09-28  本文已影响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
上一篇下一篇

猜你喜欢

热点阅读