Search code examples
iphoneuitableviewuiviewcalayeruiviewanimation

Draw graph on uiview with animation


enter image description here

Hello Everyone,

I would like to create a similar view like in the attached image. I can do this easily with the help of UITableView but I also want to draw a graph above of this tableView. I am calculating some data and based upon that data (%), I have to draw my graph on that particular row(61-70 % etc). Also when the graph reaches into specific row, i need to start the timer of that particular row also. Can i draw a CALayer above of uitableView to achieve this? or i create a custom uiview with partition and draw graphs individually by creating CALayers. Please suggest. Thanks


Solution

  • create a custom View and code init like @implementation CustomView

    - (id)initWithFrame:(CGRect)frame numberOfRows:(int)rows color:(NSArray *)colors
    {
        self = [super initWithFrame:frame];
        if (self) {
            // Initialization code
        }
        int yAxis =0;
        for(int i =0 ;i<[colors count];i++)
        {
            UIView *_v = [[UIView alloc]initWithFrame:CGRectMake(0, yAxis, 320, 480/rows)];
            [_v setBackgroundColor:[colors objectAtIndex:i]];
            [self addSubview:_v];
    
            /* add label and timer label according to your need */
    
        }
    
        return self;
    }
    

    then you can pass array of UIColors and number of rows.

    Also for graph you need to check the origin value of graph.