gpt4 book ai didi

ios - 如何设置渐变角度和类型到 CAGradientLayer

转载 作者:行者123 更新时间:2023-11-29 10:40:44 27 4
gpt4 key购买 nike

您好,我正在尝试从该颜色设置为另一个 View 的渐变中获取颜色。我可以设置开始和结束颜色,但不能设置角度和类型。

以下是值:1.开始颜色:@“2b2b2b”2.结束颜色:@“4a4a4a”3.渐变角度:904.GradientType:@"linear"

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 属性(但唯一支持的值是轴向的):

An axial gradient (also called a linear gradient) varies along an axis between two defined end points. All points that lie on a line perpendicular to the axis have the same color value.

角度由 startPointendPoint 属性决定。两者都在图层边界的单位坐标空间中定义(x 和 y 范围从 0 到 1)。

关于ios - 如何设置渐变角度和类型到 CAGradientLayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24673358/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com