将线宽设置为径向渐变

时间:2013-08-30 09:59:36

标签: 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();
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); 

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

1 个答案:

答案 0 :(得分:0)

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

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