Benoît L.
Benoît L.

Reputation: 51

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

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.

Upvotes: 1

Views: 385

Answers (2)

harsha yarabarla
harsha yarabarla

Reputation: 506

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

Upvotes: 0

zc246
zc246

Reputation: 1514

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

Upvotes: 1

Related Questions