1

I would like to draw rectangles in the background of the cells of a table view, whose size will indicate the progression of subsequent tasks:

enter image description here

The progression bar should take the whole height of the cell and its width will be programmatically set when the TableView is shown.

I would like to know how to get this result with a simple and efficient approach. I have not been able to find good practices for drawing a custom background for UITableViewCells, using CALayer or another solution.

Also, I would appreciate if the technical solution for this task could also be valid when deciding to animate the progression of the bars.

Thank you.

Benoît L.
  • 51
  • 6

2 Answers2

1

Simple solution without calculation is that, prepare a set of static different background images, and set them depend on the progress value.

zc246
  • 1,514
  • 16
  • 28
  • Thank you for your answer, but this does not seem like an elegant and scalable solution to me. I need to be able to modify the color and opacity of the progress bar, as well as provide fluid animations. – Benoît L. Nov 12 '15 at 11:10
  • Can't see why it's not elegant at all. You can still change the color and opacity to the image via code. – zc246 Nov 12 '15 at 11:31
0

Other solution requires you to create Progress view programmatically in table view's cellForRowAtIndex method and add to cell.contentView as subview

UIProgressView *progressView = [[UIProgressView alloc] init];
[progressView setFrame:cell.frame];
[cell.contentView insertSubview:progressView atIndex:0];

You can make progressview alpha property to 0.5 or some other value in order for your top views in cell.contentView to be visible properly

harsha yarabarla
  • 506
  • 4
  • 11