可能重复:
在iPhone应用程序中手动绘制渐变?
我的应用程序需要在a UIView或者背景中显示文本,UILabel但是背景必须是渐变而不是true UIColor.使用图形程序创建所需的外观并不好,因为文本可能会根据从服务器返回的数据而有所不同.
有谁知道解决这个问题的最快方法?非常感谢您的想法.
我知道CAGradientLayer目前不支持径向渐变,只能选择kCAGradientLayerAxial.
我想要下面的东西:

我一直在寻找这个问题,并发现有一种解决方法.但这些解释对我来说并不清楚.所以我想知道我是否可以使用径向渐变CAGradientLayer,如果是,那么如何做呢?
我知道如何绘制一条简单的线条:
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextMoveToPoint(context, x, y);
CGContextAddLineToPoint(context, x2, y2);
CGContextStrokePath(context);
Run Code Online (Sandbox Code Playgroud)
我知道如何做一个渐变矩形,ig:
CGColorSpaceRef myColorspace=CGColorSpaceCreateDeviceRGB();
size_t num_locations = 2;
CGFloat locations[2] = { 1.0, 0.0 };
CGFloat components[8] = { 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
CGGradientRef myGradient = CGGradientCreateWithColorComponents(myColorspace, components, locations, num_locations);
CGPoint myStartPoint, myEndPoint;
myStartPoint.x = 0.0;
myStartPoint.y = 0.0;
myEndPoint.x = 0.0;
myEndPoint.y = 10.0;
CGContextDrawLinearGradient (context, myGradient, myStartPoint, myEndPoint, 0);
Run Code Online (Sandbox Code Playgroud)
但是我怎么能画一条渐变的线条,ig从黑色渐变到白色(也可能在另一边渐渐变成黑色)?
我想创建一个右上角和左下角渐变的背景视图我该如何实现?
我有这个代码
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.bounds;
gradient.colors = [NSArray arrayWithObjects: (id)[[UIColor whiteColor] CGColor],(id)[[UIColor blackColor] CGColor], nil];
gradient.startPoint = CGPointZero;
[self.layer insertSublayer:gradient atIndex:0];
Run Code Online (Sandbox Code Playgroud)
但它没有做我想要的,我不知道如何让它做我想要的.
目前的结果:

期望的结果是:

如何在我使用的目标c(核心图形)中绘制具有径向渐变的扇区(实心圆弧)
CGContextDrawRadialGradient
Run Code Online (Sandbox Code Playgroud)
但它画圈.如果你说我如何通过径向渐变填充任何形状将是很好的.谢谢
gradient ×3
ios ×3
iphone ×3
objective-c ×2
calayer ×1
cocoa-touch ×1
draw ×1
quartz-core ×1
uiview ×1