Swift-The use of the progress bar (Uiprogressview) _ Basic usage

Source: Internet
Author: User

1, create a progress bar 

Var progressView=UIProgressView(progressViewStyle:UIProgressViewStyle.Default)
progressView.progress=0.5 //default progress 50%

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() {

/ / 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

Override func didReceiveMemoryWarning() {

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.