我为我的自定义 UIButton
创建了一个 CAGradientLayer
。创建它的代码如下:
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = btn.bounds;
gradient.cornerRadius = 10.0f;
locations=[[NSArray alloc] initWithObjects: LOC_0, LOC_5, LOC_51,LOC_1, nil];
[gradient setLocations:locations];
colorNext=[[NSArray alloc] initWithObjects:(id) G3_rgb1, (id) G3_rgb2, (id) G3_rgb3, (id) G3_rgb4, nil];
gradient.colors = colorNext;
[btn.layer insertSublayer:gradient atIndex:0];
我的问题是:按下按钮时我需要将按钮的渐变 View 更改 180 度,我应该怎么做?
最佳答案
您还可以更改渐变的起点和终点。默认起点是 {0.5, 0.0}
。默认端点是 {0.5, 1.0}
。翻转它们以使您的渐变走向另一条路。
[gradient setStartPoint:CGPointMake(0.5, 1.0)];
[gradient setEndPoint:CGPointMake(0.5, 0.0)];
将它们翻转回去以正常显示。
关于iphone - 如何将 CAGradientLayer 旋转 180 度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3658532/