Home > database >  How to put image to Progress View and make it moving with it
How to put image to Progress View and make it moving with it

Time:01-05

I'm working on the air application and there I have a progress view. How it looks now

So, I need to know, how it possible to add image to progress view and it will move together. Here is how it should look like: result

I've tried something like this: progressView.trackImage = UIImage(named: "smallPlane")

CodePudding user response:

Try the below solution, It'll definitely work for you

Step 1: Replace the ProcessView with UISlider

Step 2: UISlider provider the handle where you can set your desired image

slider.setThumbImage(UIImage(named: "Image_Name"), for: .normal)

Step 3: If you want that user not able to move handle then put the below line

slider.isUserInteractionEnabled = false

CodePudding user response:

You need to create an UIImageView and change it’s position according to the progress. For example:

let planeView = UIImageView(image: UIImage(named: "smallPlane"))
progressView.addSubview(planeView)
let leadingConstraint = planeView.leadingAnchor.constraint(equalTo: progressView.leadingAnchor)
leadingConstraint.isActive = true

Now you can change the constant of the leadingConstraint when you change the progress of progressView like that:

leadingConstraint.constant = progressView.frame.width * progress

Don’t forget to store leadingConstraint somewhere.

  • Related