I have been doing some experimenting with iOS drawing. To do a practical exercise I wrote a BarChart component. The following is the class diagram (well, I wasnt allowed to upload images) so let me write it in words. I have a NGBarChartView which inherits from UIView has 2 protocols NGBarChartViewDataSource and NGBarChartViewDelegate. And the code is at https://github.com/mraghuram/NELGPieChart/blob/master/NELGPieChart/NGBarChartView.m
To draw the barChart, I have created each barChart as a different CAShapeLayer. The reason I did this is two fold, first I could just create a UIBezierPath and attach that to a CAShapeLayer object and two, I can easily track if a barItem is touched or not by using [Layer hitTest] method. The component works pretty well. However, I am not comfortable with the approach I have taken to draw the barCharts. Hence this note. I need expert opinion on the following
- By using the CAShapeLayer and creating BarItems I am really not using the UIGraphicsContext, is this a good design?
- My approach will create several CALayers inside a UIView. Is there a limit, based on performance, to the number of CALayers you can create in a UIView.
- If a good alternative is to use CGContext* methods then, whats the right way to identify if a particular path has been touched
- From an Animation point of view, such as the Bar blinking when you tap on it, is the Layer design better or the CGContext design better.
Help is very much appreciated. BTW, you are free to look at my code and comment. I will gladly accept any suggestions to improve.
Best, Murali