iOS 坑的集中营

CAGradientLayer的简单使用

2016-11-14  本文已影响14人  踩坑小分队

简单的记录一下

- (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

盗个图.png 盗个图.png
上一篇下一篇

猜你喜欢

热点阅读