我对这个库有点困惑
https://github.com/Zedenem/UICircularSlider
我想绘制最小圆形颜色作为渐变颜色。
我已将此集成到我的项目中,并且我看到TBCircular
滑块带有渐变,但我需要对该比较进行比UICircularSlider
更多的自定义。
到目前为止,我已尝试使用`UICircularSlider'
- (CGPoint)drawCircularTrack:(float)track atPoint:(CGPoint)center withRadius:(CGFloat)radius inContext:(CGContextRef)context {
UIGraphicsPushContext(context);
CGContextBeginPath(context);
float angleFromTrack = translateValueFromSourceIntervalToDestinationInterval(track, self.minimumValue, self.maximumValue, 0, 2*M_PI);
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
CGGradientRef g[4];
CGFloat comps0[] = {1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0};
CGFloat locs[] = {0,1};
g[0] = CGGradientCreateWithColorComponents(space, comps0, locs, 2);
CGFloat comps1[] = {1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0};
g[1] = CGGradientCreateWithColorComponents(space, comps1, locs, 2);
CGFloat comps2[] = {1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0};
g[2] = CGGradientCreateWithColorComponents(space, comps2, locs, 2);
CGFloat comps3[] = {1.0,1.0,1.0,1.0,0.5,0.0,0.5,1.0};
g[3] = CGGradientCreateWithColorComponents(space, comps3, locs, 2);
CGFloat startAngle = -M_PI_2;
CGFloat endAngle = startAngle + angleFromTrack;
//CGContextMoveToPoint(context, startAngle,endAngle);
CGContextAddArc(context, center.x, center.y, radius, startAngle, endAngle, NO);
CGPoint arcEndPoint = CGContextGetPathCurrentPoint(context);
CGContextStrokePath(context);
UIGraphicsPopContext();
// CGContextDrawRadialGradient(context, g[0], CGPointMake(radius, radius), startAngle, CGPointMake(radius,radius), endAngle, 0);
CGContextClip(context);
CGContextDrawRadialGradient(context, g[0], CGPointMake(arcEndPoint.x, arcEndPoint.y),1, CGPointMake(arcEndPoint.x, arcEndPoint.y),kLineWidth, 0);
return arcEndPoint;
}
使用
获取整个视图的渐变,而不是在绘制的圆圈中CGContextAddArc(context, center.x, center.y, radius, startAngle, endAngle, NO);
我只想添加 AddArc 区域,而不是整个视图。
之后做了一些事情