How to draw a progress indicator on the background of a cell in iOS 9?

时间:2015-11-12 11:03:00

标签: ios uitableview ios9 calayer

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.

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分: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