试图使条形图成为渐变颜色,但找不到关于如何这样做的任何文档。看上去这是正确的玩法。只是需要帮助在括号中键入什么。也不关心什么颜色。
func barGradientForBarChartView(barChartView: JBBarChartView!) -> CAGradientLayer! {
}谢谢你的帮助!
发布于 2016-01-31 06:12:39
想出了这个办法。我想我会把代码发出去以防其他人需要。记住它覆盖了所有的酒吧。你不能像用实心条那样按索引把它们分开。
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
}发布于 2016-02-26 19:40:07
只是一个FYI,标题包含必要的文档。同样,自述文件也是一个很好的起点。
/**
* 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来正确地设置梯度的框架,但是您知道了。
https://stackoverflow.com/questions/34460528
复制相似问题