I have a UIProgressView and I'm giving it a progressImage that I'd like to reveal as the progress bar progresses. How can I do this?
What currently happens is the whole images always fits inside the progress bar, it just gets compressed. I'd like to, instead, just show a partial (e.g. the left side) of the image.
You'll need to create your own "custom progress view."
One approach is to use a
CALayeras a mask on the image view, adjusting the size of the layer to be a percentage of the width of the custom view.Here's a quick example...
Custom Progress View
Sample view controller
We add a "standard"
UIProgressView, an instance of our customMyProgressView, aUISliderto interactively set the progress value, and a label to show the value.Using this image for the progress view "reveal" image:
It looks like this when running:
If you want to emulate the animation capability of the default
UIProgressView(as in calling.setProgress(0.75, animated: true)) you'll have a little more work to do :)