Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gradient for bar chart is lost / sizing problem #158

Closed
ArminGrau opened this issue Apr 17, 2015 · 2 comments
Closed

gradient for bar chart is lost / sizing problem #158

ArminGrau opened this issue Apr 17, 2015 · 2 comments

Comments

@ArminGrau
Copy link

I'm trying to add a gradient to my bars, but it is not visible.
The problem seems to be that at initialization time the bounds of the bar are not yet set (that comes later, in line 205 of JBBarChartView.m), so the gradient frame is always {0,0,0,0}.
Do you have an idea how to change this or work around it?
Thanks, Armin

Here's my code:

func barChartView(barChartView: JBBarChartView!, barViewAtIndex index: UInt) -> UIView! {
    let barView = BarChartBarView()
    ...
    return barView
}

class BarChartBarView: UIView {

var gradient = CAGradientLayer()

override init(frame: CGRect) {
    super.init(frame: frame)

    ...
    gradient.colors = [ UIColorFromRGB(0xF26E5E).CGColor, UIColorFromRGB(0xFD3968).CGColor]
    gradient.locations = [0.0 , 1.0]
    gradient.startPoint = CGPoint(x: 0.0, y: 0.0)
    gradient.endPoint = CGPoint(x: 1.0, y: 1.0)
    gradient.frame = self.bounds
    self.layer.insertSublayer(gradient, atIndex: 0)
}

}

@terryworona
Copy link
Collaborator

Re-set your gradients frame in layout subviews.

func layoutSubviews() 
{
    gradient.frame = self.bounds
}

@ArminGrau
Copy link
Author

should have thought of that - thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants