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

colors array not initialized when using nib/storyboard #8

Closed
swift-js opened this issue Jan 7, 2015 · 1 comment
Closed

colors array not initialized when using nib/storyboard #8

swift-js opened this issue Jan 7, 2015 · 1 comment

Comments

@swift-js
Copy link

swift-js commented Jan 7, 2015

When using nib or storyboard to create custom view with class 'LineChart', then only "init(coder aDecoder: NSCoder)" is called, not "init(frame: CGRect)". This means the initialization code for "self.colors" is never called and app will crash during "drawLine" at "layer.strokeColor = colors[lineIndex].CGColor"

@07cs07
Copy link

07cs07 commented Jan 12, 2015

Below code will fix the issue, initialising the colour in override function of awakeFromNib
override func awakeFromNib() { super.awakeFromNib() self.backgroundColor = UIColor.clearColor() self.colors = [ UIColorFromHex(0x1f77b4), UIColorFromHex(0xff7f0e), UIColorFromHex(0x2ca02c), UIColorFromHex(0xd62728), UIColorFromHex(0x9467bd), UIColorFromHex(0x8c564b), UIColorFromHex(0xe377c2), UIColorFromHex(0x7f7f7f), UIColorFromHex(0xbcbd22), UIColorFromHex(0x17becf) ] }

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