//联系人:石虎QQ: 1224614774昵称:嗡嘛呢叭咪哄
一、CAGradientLayer 效果图
二、代码实现
//
// ViewController.m
// CAGradientLayer~demo1
//
// Created by石虎on 2017/9/5.
// Copyright © 2017年石虎. All rights reserved.
//
#import"ViewController.h"
@interfaceViewController()
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
CAGradientLayer*colorLayer = [CAGradientLayerlayer];
colorLayer.frame= (CGRect){CGPointZero,CGSizeMake(400,600)};
colorLayer.position=self.view.center;
[self.view.layeraddSublayer:colorLayer];
//颜色分配
colorLayer.colors=@[(__bridgeid)[UIColorredColor].CGColor,
(__bridgeid)[UIColorgreenColor].CGColor,
(__bridgeid)[UIColororangeColor].CGColor,
(__bridgeid)[UIColoryellowColor].CGColor,
(__bridgeid)[UIColormagentaColor].CGColor,
(__bridgeid)[UIColorpurpleColor].CGColor,
(__bridgeid)[UIColorbrownColor].CGColor,
(__bridgeid)[UIColorblueColor].CGColor];
//颜色分割线
colorLayer.locations=@[@(0.15),@(0.3),@(0.45),@(0.55),@(0.65),@(0.75)];
//起始点
colorLayer.startPoint=CGPointMake(0,0);
//结束点(垂直)
//colorLayer.endPoint = CGPointMake(1, 0);
//结束点(45度)
colorLayer.endPoint=CGPointMake(1,1);
}
@end