圆形渐变色"非线性"在UIView

时间:2014-12-04 12:05:14

标签: ios objective-c uiview layer cagradientlayer

我对渐变颜色有疑问,我不能使渐变颜色显示为圆形,它总是看起来像线性,我需要下图中的精确渐变:

enter image description here

PS:这是我使用的代码:

UIView *view = [[UIView alloc] initWithFrame:self.view.frame];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = view.bounds;
gradient.startPoint = CGPointMake(0.0,0.4);
gradient.endPoint = CGPointMake(0.0,0.6);
view.layer.masksToBounds = YES;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:153.0/255.0 green:204.0/255.0 blue:0.0/255.0 alpha:1.0] CGColor], (id)[[UIColor whiteColor] CGColor], nil];
[view.layer insertSublayer:gradient atIndex:0];
[self.view addSubview:view];

1 个答案:

答案 0 :(得分:-1)

CGContext中有一个CGContextDrawRadialGradient。我希望它会对你有所帮助