嗨,我正在尝试从将颜色设置为另一种视图的渐变中获取颜色。
我可以设置开始和结束颜色,但不能设置角度和类型。
以下是这些值:
1.Startcolor:@“2b2b2b”
2.Endcolor:@“4a4a4a”
3.GradientAngle:90
4.GradientType:@“线性”
UIView *theView=[[UIView alloc] init];
theView.frame=self.view.frame;
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = theView.bounds;
UIColor *startColor = [self colorwithHexString:@"2b2b2b" alpha:1];
UIColor *endColor = [self colorwithHexString:@"4a4a4a" alpha:1];
gradient.colors = [NSArray arrayWithObjects:(id)[startColor CGColor], (id)[endColor CGColor], nil];
[theView.layer insertSublayer:gradient atIndex:0];
最佳答案
CAGradientLayer具有type
属性(但唯一支持的值是axis):
轴向梯度(也称为线性梯度)沿轴线在两个定义的端点之间变化。垂直于轴的线上的所有点都具有相同的颜色值。
角度由startPoint
和endPoint
属性确定。两者都在图层边界的单位坐标空间中定义(x和y范围为0到1)。
关于ios - 如何设置渐变角度并输入到CAGradientLayer,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24673358/