问题 I have created CAGradientLayer having three colors, i need to give each color different locations. Example: Red = 0 to 50 % Yellow = 51 to 80 % Green = 81 to 100 % I have tried with giving startPoint and endPoint but it did not work. 回答1: If you put the following code into a Playground you will get the exact desired output: let view = UIView(frame: CGRectMake(0,0,200,100)) let layer = CAGradientLayer() layer.frame = view.frame layer.colors = [UIColor.greenColor().CGColor, UIColor.yellowColor(