Swift - UIProgressView fills diagonally

2.4k views Asked by At

So I set up a UIProgressView to fill after 3 seconds as well as increasing the height of the bar a bit. However when it fills up, it fills diagonally as opposed to just filling from one side to the other. The bar starts in the top right corner and then expands to fill the progress view just before it ends.

This is the code I am using:

import UIKit

class LoadingScreen: UIViewController {


    @IBOutlet weak var progressView: UIProgressView!


    override func viewDidLoad() {
        super.viewDidLoad()

        UIView.animateWithDuration(3, animations: { () -> Void in
            self.progressView.setProgress(1.0, animated: true)
        })

        progressView.transform = CGAffineTransformScale(progressView.transform, 1, 10)

}


}

Here are some screenshots:

enter image description here enter image description here enter image description here

2

There are 2 answers

1
Bannings On

It seems that the size of the progressView is incorrect.

Try to put these code in viewDidLayoutSubviews:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    UIView.animateWithDuration(3, animations: { () -> Void in
        self.progressView.setProgress(1.0, animated: true)
    })

    progressView.transform = CGAffineTransformScale(progressView.transform, 1, 10)
}
0
dhour On

Coming to this rather late but I just experienced this and fixed it by changing my progressView style to .Bar. Hope that helps!

let progressView = UIProgressView(progressViewStyle: .Bar)