Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将线宽设置为径向渐变_Ios_Core Graphics_Radial Gradients - Fatal编程技术网

Ios 将线宽设置为径向渐变

Ios 将线宽设置为径向渐变,ios,core-graphics,radial-gradients,Ios,Core Graphics,Radial Gradients,我用径向梯度画圆。它工作正常,但现在我想设置边框颜色和边框宽度。我试过了,但不起作用 这是我的密码 CGGradientRef gradient; CGColorSpaceRef colorSpace; CGFloat locations[] = {0.0,1.0}; CGFloat components[] = { red2,green2,blue2,1.0,red1,green1,blue1,1.0 }; colorSpace = CGColorSpaceCreateDeviceRGB()

我用径向梯度画圆。它工作正常,但现在我想设置边框颜色和边框宽度。我试过了,但不起作用

这是我的密码

CGGradientRef gradient;
CGColorSpaceRef colorSpace;
CGFloat locations[] = {0.0,1.0};
CGFloat components[] = { red2,green2,blue2,1.0,red1,green1,blue1,1.0  };
colorSpace = CGColorSpaceCreateDeviceRGB();
gradient = CGGradientCreateWithColorComponents(colorSpace,components,locations,
                                               sizeof(locations)/sizeof(CGFloat));

CGPoint start = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2 ), end = CGPointMake(self.bounds.size.width/2 , self.bounds.size.height/2);
CGFloat startRadius = 0.0, endRadius = radius;
CGContextDrawRadialGradient(contextRef,gradient,start,startRadius,end,endRadius,0);
CGContextSetLineWidth(contextRef, 5.0);
CGGradientRelease(gradient);
CGColorSpaceRelease(colorSpace); 

如何设置边框颜色和宽度?

首先添加
QuartzCore
框架,然后尝试此代码

[[Firstbtn layer]setBorderColor:[[UIColor blackColor]CGColor]];
    [[self.Firstbtn layer]setBorderWidth:2.3];
    [[self.Firstbtn layer]setCornerRadius:15];

没有办法使用cgcontextref吗?