1

I'm using a UIProgressView and want to stick a image subview to the progress % as in the image below:

enter image description here

I want to get the co-ordinate of the progress tint and red subview as in the figure to "stick" with the progress tint, whatever the progress will be..

Shobhakar Tiwari
  • 7,862
  • 4
  • 36
  • 71
Aashish
  • 2,532
  • 2
  • 23
  • 28

1 Answers1

1

You can start by vertically centering the image view with the progress view using constraints or programmatically like below.

imageView.center.y = progressView.center.y

Then where ever you are updating the progress, after you can calculate the center x coordinate for the image view using the adjusted progress and width of the progress view.

imageView.center.x = progressView.progress * progressView.frame.width

Although you may need to add padding if the progress view's super view is not the same width.

OR

You could consider using a UISlider; it comes with a progress-bar-like track and a thumb slider that you can customise. This way, you can even have user interaction if need be - otherwise user interaction can be disabled and you can set the progress programmatically.

Callam
  • 11,409
  • 2
  • 34
  • 32
  • Thanks @Callam for your answer, but I have a different scenario; I want to embed a progressView and UISlider, so I was thinking to 'stick' the UISlider just with the progress tint on progress view.. so that the image subview will always attach to the progress tint and slider origin will start from the exact point. Will it be possible – Aashish Dec 17 '16 at 11:19
  • But with above code, the image subview do not attach with the progress tint, as progress changes.. am i missing something? – Aashish Dec 17 '16 at 11:20