1, create a progress bar
Var progressView=UIProgressView(progressViewStyle:UIProgressViewStyle.Default)
progressView.center=self.view.center
progressView.progress=0.5 //default progress 50%
self.view.addSubview(progressView);
2, set the progress, simultaneously has the animation effect
progressview.setprogress (0.8,animated:true)
3, change the progress bar color
progressView.progressTintColor=UIColor.greenColor() //There is a progress color
progressView.trackTintColor=UIColor.blueColor() //Remaining progress color (ie progress slot color)
4, set the width of the Progressview (progress bar length) Normally, we can set its width (progress bar length) with the Frame property when initializing Progressview.
For example, I placed a progress bar with a horizontal width of 200 on the screen, centered horizontally.
self.view.addSubview(myProgressView)
}
Override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
5, set the height of the progressView
But we will find that the height of the progressView will not change anyway, regardless of the height of the progressView. So if you want to change the height, you can change your mind and change it by changing the scale of the progressView.
The following example adjusts the progress bar height to the default of 5 times.
Import UIKit
Class ViewController: UIViewController {
Override func viewDidLoad() {
super.viewDidLoad()
/ / Set the background to black
self.view.backgroundColor = UIColor.blackColor()
/ / Create a progress bar with a width of 200
Let myProgressView = UIProgressView(frame: CGRectMake(0, 0, 200, 10))
/ / Set the progress bar position (horizontal centered)
myProgressView.layer.position = CGPoint(x: self.view.frame.width/2, y: 100)
/ / Change the height of the progress bar by deformation (the horizontal width does not change, the vertical height becomes the default 5 times)
myProgressView.transform = CGAffineTransformMakeScale(1.0, 5.0)
/ / progress bar progress
myProgressView.progress = 0.3
/ / Add the progress bar to the view
self.view.addSubview(myProgressView)
}
Override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}