Reputation: 139
I need to draw a chart which one cell has a line link to another cell, How can I do that in UITableViewCell? like below:
Upvotes: 0
Views: 70
Reputation: 9965
Something like this?
NSIndexPath *iPathCellFrom = [NSIndexPath indexPathForRow:0 inSection:0];
NSIndexPath *iPathCellTo = [NSIndexPath indexPathForRow:0 inSection:0];
CGRect from = [self.myTableView rectForRowAtIndexPath:iPathCellFrom];
CGRect to = [self.myTableView rectForRowAtIndexPath:iPathCellTo];
CGPoint fromCenter = CGPointMake(from.origin.x + from.size.width/2, from.origin.y + from.size.height/2);
CGPoint toCenter = CGPointMake(to.origin.x + to.size.width/2, to.origin.y + to.size.height/2);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextSetStrokeColorWithColor(context, [[UIColor blackColor]CGColor]);
CGContextSetLineWidth(context, 1.0);
CGContextMoveToPoint(context, fromCenter.x, fromCenter.y);
CGContextAddLineToPoint(context, toCenter.x, toCenter.y);
CGContextStrokePath(context);
CGContextRestoreGState(context);
Context code taken from here
Upvotes: 0
Reputation: 77621
I'd use a UICollectionView
instead of a table view.
Each cell will then contain one number.
You can then use the frame of each cell (and the current offset of the scroll view) to find the centre of each relevant cell.
Then use a view placed over the UICollectionViewCell
and draw onto that.
Upvotes: 1