CAGradientLayer的简单使用

简单的记录一下

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self createUI];
    
}

// 创建界面
- (void)createUI
{
    CAGradientLayer *layer = [CAGradientLayer layer];
    layer.frame = CGRectMake(100, 100, 100, 100);
    
    // 进行颜色分配
    UIColor *green = [UIColor greenColor];
    UIColor *yellow = [UIColor yellowColor];
    UIColor *red = [UIColor redColor];
    layer.colors = @[(__bridge id)green.CGColor,(__bridge id)yellow.CGColor,(__bridge id)red.CGColor];
    
    // 设置颜色分割线
    layer.locations = @[@(0.25),@(0.5),@(0.75)];
    
    // 设置起始点
    layer.startPoint = CGPointMake(0, 0);
    layer.endPoint = CGPointMake(1, 0);
    
    [self.view.layer addSublayer:layer];
}

http://blog.csdn.net/ys410900345/article/details/43270609

CAGradientLayer的简单使用_第1张图片
盗个图.png

CAGradientLayer的简单使用_第2张图片
盗个图.png

你可能感兴趣的:(CAGradientLayer的简单使用)