0

I create progress bar in my app using this code:

let progressBar = UIProgressView(progressViewStyle: .default)
progressBar.setProgress(1.0, animated: true)
self.addSubview(progressBar)

progressBar.trackTintColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.2)
progressBar.tintColor = .white

let frame = CGRect(x: percentLabel.intrinsicContentSize.width + 30.0, y: 117, width: 254, height: 3)
progressBar.frame = frame

And as you can see here:screenshot2 screenshot1 If the progress is 1.0, progress bar goes beyond the frame. Any ideas how to fix that??

Egor Iskrenkov
  • 433
  • 4
  • 15

1 Answers1

3

the percentLabel is pushing it to the right.

To fix this, you could constrain the progress bar to always start at the position that it has in the second photo. Add a leading constraint from the progress bar to its superview. And also give it a smaller width.

Hope this helps.

Vlad M.
  • 139
  • 4
  • OMG, how could I not notice that :) Thank you, but then I have one more related question: why there are rounded corners on the left side of the progress bar, but on the right side they are simple? How to make them rounded too? – Egor Iskrenkov Sep 03 '18 at 14:10
  • Fixed that: 'progressBar.layer.cornerRadius = 1.5', thank you again – Egor Iskrenkov Sep 03 '18 at 14:48