尝试使条形为渐变颜色,但无法找到有关如何执行此操作的任何文档。看起来这是正确的功能。只需要在括号中键入内容需要帮助。不关心真正的颜色。
func barGradientForBarChartView(barChartView: JBBarChartView!) -> CAGradientLayer! {
}
感谢您的帮助!
答案 0 :(得分:0)
管理好了解决这个问题。想我会发布任何其他人需要的代码。请记住,它涵盖了所有的酒吧。您无法通过索引将它们与实心条分开。
func barGradientForBarChartView(barChartView: JBBarChartView) -> CAGradientLayer {
let topColor = UIColor.orangeColor()
let bottomColor = UIColor.blueColor()
let gradientColors: [CGColor] = [topColor.CGColor, bottomColor.CGColor]
let gradientLocations: [Float] = [0.0, 1.0]
let gradientLayer: CAGradientLayer = CAGradientLayer()
gradientLayer.colors = gradientColors
gradientLayer.locations = gradientLocations
return gradientLayer
}
答案 1 :(得分:0)
标题包含必要文档的仅供参考。同样,README是一个很好的起点。
/**
* If you already implement barChartView:barViewAtIndex: delegate - this method has no effect.
* If a custom UIView isn't supplied and barChartView:colorForBarViewAtIndex: isn't implemented, then
* a gradient layer may be supplied to be used across all bars within the chart.
*
* Default: black color.
*
* @param barChartView The bar chart object requesting this information.
*
* @return The gradient layer to be used as a mask over all bars within the chart.
*/
最后,您可以使用barViewAtIndex:在每个条形基础上创建渐变,并返回带有渐变的自定义视图。
样品:
- (UIView *)barChartView:(JBBarChartView *)barChartView barViewAtIndex:(NSUInteger)index
{
UIView *customBarView = [[UIView alloc] init];
CAGradientLayer *gradient = [CAGradientLayer new];
gradient.startPoint = CGPointMake(0.0, 0.0);
gradient.endPoint = CGPointMake(1.0, 0.0);
gradient.colors = @[(id)[UIColor redColor].CGColor, (id)[UIColor greenColor].CGColor];
[customBarView.layer insertSublayer:gradient atIndex:0];
return customBarView;
}
当然,customView应该是UIView的子类,你应该实现layoutSubviews来正确设置渐变的框架,但你明白了。